summaryrefslogtreecommitdiffstats
path: root/ksim/monitors/filesystem
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /ksim/monitors/filesystem
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksim/monitors/filesystem')
-rw-r--r--ksim/monitors/filesystem/DFree.desktop87
-rw-r--r--ksim/monitors/filesystem/Makefile.am16
-rw-r--r--ksim/monitors/filesystem/configure.in.in2
-rw-r--r--ksim/monitors/filesystem/filesystemstats.cpp224
-rw-r--r--ksim/monitors/filesystem/filesystemstats.h40
-rw-r--r--ksim/monitors/filesystem/filesystemwidget.cpp232
-rw-r--r--ksim/monitors/filesystem/filesystemwidget.h78
-rw-r--r--ksim/monitors/filesystem/fsystemconfig.cpp184
-rw-r--r--ksim/monitors/filesystem/fsystemconfig.h58
-rw-r--r--ksim/monitors/filesystem/fsystemiface.h32
-rw-r--r--ksim/monitors/filesystem/ksimfsystem.cpp202
-rw-r--r--ksim/monitors/filesystem/ksimfsystem.h76
12 files changed, 1231 insertions, 0 deletions
diff --git a/ksim/monitors/filesystem/DFree.desktop b/ksim/monitors/filesystem/DFree.desktop
new file mode 100644
index 0000000..78ffdb1
--- /dev/null
+++ b/ksim/monitors/filesystem/DFree.desktop
@@ -0,0 +1,87 @@
+[Desktop Entry]
+Icon=hdd_unmount
+Name=DFree
+Name[af]=Dfree
+Name[bg]=Дялове
+Name[ca]=Disc lliure
+Name[cs]=Volný disk
+Name[eo]=Diskuzo
+Name[et]=Vaba kettaruum
+Name[he]=מחיצות
+Name[hi]=डी-फ्री
+Name[it]=Disco libero
+Name[kk]=Тіркеген бөлімдер
+Name[ko]=디스크 사용량
+Name[ne]=डिफ्रि
+Name[pt_BR]=Disco Livre
+Name[ru]=Смонтированные разделы
+Name[sk]=Voľný disk
+Name[sv]=Ledigt diskutrymme
+Name[ta]= Dபிரீ
+Name[tg]=DОзод
+Name[th]=พื้นที่ว่างของดิสก์
+Comment=Mounted Partitions Monitor
+Comment[af]=Gekoppelde Partisies Monitor
+Comment[ar]=مراقب الأقسام المضمومة
+Comment[bg]=Мониторинг на монтираните дялове
+Comment[bs]=Nadzor montiranih particija
+Comment[ca]=Monitor de les particions muntades
+Comment[cs]=Monitor připojených diskových oddílů
+Comment[cy]=Monitr Rhaniadau Mowntiedig
+Comment[da]=Overvågning af monterede partitioner
+Comment[de]=Anzeige für eingebundene Laufwerke
+Comment[el]=Επόπτης προσαρτημένων κατατμήσεων
+Comment[eo]=Vidigilo por la kroĉitaj subdiskoj
+Comment[es]=Monitor de particiones montadas
+Comment[et]=Ühendatud partitsioonide monitooring
+Comment[eu]=Muntatutako Partizioen Begiralea
+Comment[fa]=نمایشگر افرازهای سوارشده
+Comment[fi]=Liitettyjen osioiden valvonta
+Comment[fr]=Surveillant des lecteurs montés
+Comment[ga]=Monatóir Rannta Feistithe
+Comment[he]=צג מחיצות מחוברות
+Comment[hi]=माउन्टेड पार्टीशन्स मॉनीटर
+Comment[hu]=Lemezcsatlakoztatás-figyelő
+Comment[is]=Eftirlit með tengdum disksneiðum
+Comment[it]=Controllo delle partizioni montate
+Comment[ja]=マウントされたパーティションのモニタ
+Comment[ka]= მონტირებული პარტიციების მონიტორი
+Comment[kk]=Тіркеген бөлімдерді бақылау
+Comment[km]=កម្មវិធី​ត្រួតពិនិត្យ​ភាគ​ដែល​បាន​ម៉ោន
+Comment[lt]=Sumontuotų skirsnių stebėtojas
+Comment[mk]=Монитор на монтираните партиции
+Comment[ms]=Pemerhati Partisi yang telah Dilekapkan
+Comment[nb]=Overvåkning av monterte partisjoner
+Comment[nds]=Kieker för inhangte Partitschonen
+Comment[ne]=माउन्ट गरिएको विभाजन मोनिटर
+Comment[nl]=Monitor van aangekoppelde partities
+Comment[nn]=Overvaking av monterte partisjonar
+Comment[pa]=ਮਾਊਂਟ ਭਾਗ ਨਿਗਰਾਨ
+Comment[pl]=Stan zamontowanych partycji
+Comment[pt]=Monitor de Partições Montadas
+Comment[pt_BR]=Monitor das Partições Montadas
+Comment[ro]=Monitor partiţii montate
+Comment[ru]=Монитор смонтированных разделов
+Comment[sk]=Monitor pripojených diskových oddielov
+Comment[sl]=Nadzornik priklopljenih razdelkov
+Comment[sr]=Надгледање монтираних партиција
+Comment[sr@Latn]=Nadgledanje montiranih particija
+Comment[sv]=Övervakar monterade partitioner
+Comment[ta]=ஏற்றப்பட்ட பகுக்கப்பட்ட கண்காணி
+Comment[tg]=Дидабони Қисмҳои Насбшуда
+Comment[th]=สอดส่องพาร์ติชันที่เมานท์ไว้แล้ว
+Comment[tr]=Bağlanmış Disk Bölümü İzleyici
+Comment[uk]=Монітор змонтованих розділів
+Comment[uz]=Diskning ulangan qismlarini nazorat qilish plagini
+Comment[uz@cyrillic]=Дискнинг уланган қисмларини назорат қилиш плагини
+Comment[wa]=Corwaitoe des montêyès pårticions
+Comment[xh]=Ulwahlulo Lonyuso lwe Monitor
+Comment[zh_CN]=已挂载分区监视器
+Comment[zh_TW]=已掛載的分割區監視器
+Comment[zu]=Umlawuli Wezahlukaniso Ezinyukile
+X-KSIM-VERSION=0.1
+X-KSIM-LIBRARY=filesystem
+X-KSIM-PREFS=File System
+X-KSIM-AUTHOR=Robbie Ward
+X-KSIM-EMAIL=linuxphreak@gmx.co.uk
+X-KSIM-COPYRIGHT=(C) 2001 Robbie Ward
diff --git a/ksim/monitors/filesystem/Makefile.am b/ksim/monitors/filesystem/Makefile.am
new file mode 100644
index 0000000..7da7012
--- /dev/null
+++ b/ksim/monitors/filesystem/Makefile.am
@@ -0,0 +1,16 @@
+kde_module_LTLIBRARIES = ksim_filesystem.la
+ksim_filesystem_la_SOURCES = ksimfsystem.cpp fsystemconfig.cpp \
+ fsystemiface.skel filesystemwidget.cpp filesystemstats.cpp
+
+ksim_filesystem_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+ksim_filesystem_la_LIBADD = ../../library/libksimcore.la
+
+EXTRA_DIST = DFree.desktop
+
+INCLUDES= -I$(top_srcdir)/ksim/library \
+ $(all_includes)
+
+METASOURCES = AUTO
+
+mon_DATA = DFree.desktop
+mondir = $(kde_datadir)/ksim/monitors
diff --git a/ksim/monitors/filesystem/configure.in.in b/ksim/monitors/filesystem/configure.in.in
new file mode 100644
index 0000000..8fd7a61
--- /dev/null
+++ b/ksim/monitors/filesystem/configure.in.in
@@ -0,0 +1,2 @@
+AC_CHECK_HEADERS(sys/mnttab.h mntent.h sys/statvfs.h sys/statfs.h sys/vfs.h sys/mount.h sys/ucred.h sys/loadavg.h)
+AC_CHECK_FUNCS(statvfs)
diff --git a/ksim/monitors/filesystem/filesystemstats.cpp b/ksim/monitors/filesystem/filesystemstats.cpp
new file mode 100644
index 0000000..eeb5c62
--- /dev/null
+++ b/ksim/monitors/filesystem/filesystemstats.cpp
@@ -0,0 +1,224 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "filesystemstats.h"
+
+#include <qglobal.h>
+#include <qfile.h>
+#include <qstringlist.h>
+
+#include <kdebug.h>
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#if defined(HAVE_SYS_STATVFS_H) && !defined(__DragonFly__)
+#include <sys/statvfs.h>
+#elif defined( HAVE_SYS_STATFS_H )
+#include <sys/statfs.h>
+#endif
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
+#endif
+#ifdef HAVE_SYS_MOUNT_H
+#include <sys/mount.h>
+#endif
+#ifdef HAVE_MNTENT_H
+#include <mntent.h>
+#ifdef _HPUX_SOURCE
+#define _PATH_MOUNTED MNTTAB
+#endif
+#endif
+#ifdef HAVE_SYS_UCRED_H
+#include <sys/ucred.h>
+#endif
+#ifdef HAVE_SYS_MNTTAB_H
+#include <sys/mnttab.h>
+#undef HAVE_MNTENT_H
+#define _PATH_MOUNTED MNTTAB
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+
+#if defined(HAVE_STATVFS) && !defined(__DragonFly__)
+typedef struct statvfs ksim_statfs;
+#define ksim_getfsstat getvfsstat
+#elif defined( HAVE_STATFS ) || defined( Q_OS_FREEBSD )
+typedef struct statfs ksim_statfs;
+#define ksim_getfsstat getfsstat
+#else
+typedef struct // fall back for (possibly) non-supported systems
+{
+ int f_blocks;
+ int f_bfree;
+} ksim_statfs;
+#endif
+
+int fsystemStats( const char * file, ksim_statfs & stats )
+{
+#if defined(HAVE_STATVFS) && !defined(__DragonFly__)
+ return statvfs( file, &stats );
+#elif defined( HAVE_STATFS ) || defined( Q_OS_FREEBSD )
+ return statfs( file, &stats );
+#else // fall back for (possibly) non-supported systems
+ (void)file;
+
+ stats.f_blocks = 0;
+ stats.f_bfree = 0;
+ return -1;
+#endif
+}
+
+#ifdef HAVE_SYS_MNTTAB_H
+#define USE_MNTENT
+
+typedef struct
+{
+ const char * mnt_dir;
+ const char * mnt_fsname;
+ const char * mnt_type;
+} ksim_mntent;
+
+FILE * setmntent( const char * mtab, const char * mode )
+{
+ return fopen( mtab, mode );
+}
+
+int endmntent( FILE * file )
+{
+ return fclose( file );
+}
+
+ksim_mntent * ksim_getmntent( FILE * file )
+{
+ ksim_mntent * entry;
+ struct mnttab tab;
+
+ if ( getmntent( file, &tab ) != 0 )
+ return NULL;
+
+ entry = new ksim_mntent;
+ entry->mnt_dir = tab.mnt_mountp;
+ entry->mnt_fsname = tab.mnt_special;
+ entry->mnt_type = tab.mnt_fstype;
+ return entry;
+}
+
+#define delete_mntent( x ) delete x
+#elif defined( HAVE_MNTENT_H )
+#define USE_MNTENT
+
+// Dummy setup
+typedef struct mntent ksim_mntent;
+ksim_mntent * ksim_getmntent( FILE * file )
+{
+ return getmntent( file );
+}
+
+#define delete_mntent( x )
+#elif defined( HAVE_SYS_UCRED_H ) || defined( HAVE_SYS_MOUNT_H )
+#define USE_FSSTAT
+#else
+#define USE_FAILSAFE
+#endif
+
+FilesystemStats::List FilesystemStats::readEntries()
+{
+ List list;
+
+#ifdef USE_MNTENT
+ FILE * fp = setmntent( _PATH_MOUNTED, "r" );
+ ksim_mntent * point;
+
+ while ( ( point = ksim_getmntent( fp ) ) != 0 )
+ {
+ Entry entry;
+ entry.dir = point->mnt_dir;
+ entry.fsname = point->mnt_fsname;
+ entry.type = point->mnt_type;
+ list.append( entry );
+
+ delete_mntent( point );
+ }
+
+ endmntent( fp );
+#endif
+
+#ifdef USE_FSSTAT
+ ksim_statfs sfs[32];
+ int fs_count;
+ if ( ( fs_count = ksim_getfsstat( sfs, sizeof( sfs ), 0 ) ) != -1 )
+ {
+ for ( int i = 0; i < fs_count; i++ )
+ {
+ Entry entry;
+ entry.dir = sfs[i].f_mntonname;
+ entry.fsname = sfs[i].f_mntfromname;
+
+#ifndef __osf__
+ entry.type = sfs[i].f_fstypename;
+#endif
+
+ list.append( entry );
+ }
+ }
+#endif
+
+#ifdef USE_FAILSAFE
+ QFile file( QString::fromLatin1( _PATH_MOUNTED ) );
+
+ if ( !file.open( IO_ReadOnly ) )
+ return list;
+
+ QTextStream stream( &file );
+
+ while ( !stream.atEnd() )
+ {
+ QStringList line = QStringList::split( " ", stream.readLine() );
+
+ Entry entry;
+ entry.dir = line[1].stripWhiteSpace();
+ entry.fsname = line[0].stripWhiteSpace();
+ entry.type = line[2].stripWhiteSpace();
+ list.append( entry );
+ }
+#endif
+
+ return list;
+}
+
+bool FilesystemStats::readStats( const QString & mntPoint, int & totalBlocks, int & freeBlocks )
+{
+ ksim_statfs sysStats;
+ if ( fsystemStats( QFile::encodeName( mntPoint ).data(), sysStats ) < 0 )
+ {
+ kdError() << "While reading filesystem information for " << mntPoint << endl;
+ totalBlocks = 0;
+ freeBlocks = 0;
+ }
+
+ totalBlocks = sysStats.f_blocks;
+ freeBlocks = sysStats.f_bfree;
+
+ // Return true if our filesystem is statable
+ return totalBlocks > 0;
+}
diff --git a/ksim/monitors/filesystem/filesystemstats.h b/ksim/monitors/filesystem/filesystemstats.h
new file mode 100644
index 0000000..3ea8f74
--- /dev/null
+++ b/ksim/monitors/filesystem/filesystemstats.h
@@ -0,0 +1,40 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef FILESYSTEMSTATS_H
+#define FILESYSTEMSTATS_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+namespace FilesystemStats
+{
+ struct Entry
+ {
+ QString dir;
+ QString fsname;
+ QString type;
+ };
+
+ typedef QValueList<Entry> List;
+ List readEntries();
+ bool readStats( const QString &, int &, int & );
+
+}
+#endif
diff --git a/ksim/monitors/filesystem/filesystemwidget.cpp b/ksim/monitors/filesystem/filesystemwidget.cpp
new file mode 100644
index 0000000..0428ee3
--- /dev/null
+++ b/ksim/monitors/filesystem/filesystemwidget.cpp
@@ -0,0 +1,232 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "filesystemwidget.h"
+
+#include <pluginmodule.h>
+
+#include <qlayout.h>
+#include <qpopupmenu.h>
+#include <qregexp.h>
+#include <qcursor.h>
+
+#include <kprocess.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kdebug.h>
+
+FilesystemWidget::Filesystem::Filesystem()
+{
+ m_display = 0;
+}
+
+FilesystemWidget::Filesystem::Filesystem(KSim::Progress *display,
+ const QString &point)
+{
+ m_display = display;
+ m_mountPoint = point;
+}
+
+FilesystemWidget::Filesystem::~Filesystem()
+{
+ delete m_display;
+}
+
+KSim::Progress *FilesystemWidget::Filesystem::display() const
+{
+ return m_display;
+}
+
+const QString &FilesystemWidget::Filesystem::mountPoint() const
+{
+ return m_mountPoint;
+}
+
+const QString &FilesystemWidget::Filesystem::text() const
+{
+ return m_display->text();
+}
+
+int FilesystemWidget::Filesystem::value() const
+{
+ return m_display->value();
+}
+
+void FilesystemWidget::Filesystem::setText(const QString &text)
+{
+ if (!m_display)
+ return;
+
+ m_display->setText(text);
+}
+
+void FilesystemWidget::Filesystem::setValue(int value)
+{
+ if (!m_display)
+ return;
+
+ m_display->setValue(value);
+}
+
+FilesystemWidget::FilesystemWidget(QWidget *parent, const char *name)
+ : QWidget(parent, name)
+{
+ m_list.setAutoDelete(true);
+ m_layout = new QVBoxLayout(this);
+ m_process = 0;
+}
+
+FilesystemWidget::~FilesystemWidget()
+{
+ delete m_process;
+}
+
+void FilesystemWidget::append(int max, const QString &mountPoint)
+{
+ KSim::Progress *progress = new KSim::Progress(max, this);
+ progress->installEventFilter(this);
+ progress->show();
+ m_layout->addWidget(progress);
+
+ m_list.append(new Filesystem(progress, mountPoint));
+}
+
+void FilesystemWidget::setText(uint id, const QString &text)
+{
+ if (id > m_list.count())
+ return;
+
+ m_list.at(id)->setText(text);
+}
+
+void FilesystemWidget::setValue(uint id, int value)
+{
+ if (id > m_list.count())
+ return;
+
+ m_list.at(id)->setValue(value);
+}
+
+void FilesystemWidget::clear()
+{
+ m_list.clear();
+}
+
+bool FilesystemWidget::eventFilter(QObject *o, QEvent *e)
+{
+ if (!o->isA("KSim::Progress"))
+ return QWidget::eventFilter(o, e);
+
+ KSim::Progress *progressBar = 0;
+ int i = 0;
+ QPtrListIterator<Filesystem> it(m_list);
+ Filesystem *filesystem;
+ while ((filesystem = it.current()) != 0) {
+ ++it;
+
+ if (filesystem->display() == o) {
+ progressBar = filesystem->display();
+ break;
+ }
+
+ ++i;
+ }
+
+ if (o == progressBar && e->type() == QEvent::MouseButtonPress)
+ {
+ switch(static_cast<QMouseEvent *>(e)->button()) {
+ case QMouseEvent::RightButton:
+ showMenu(i);
+ break;
+ default:
+ break;
+ case QMouseEvent::LeftButton:
+ if (parentWidget()->inherits("KSim::PluginView"))
+ static_cast<KSim::PluginView *>(parentWidget())->doCommand();
+ break;
+ }
+
+ return true;
+ }
+
+ return QWidget::eventFilter(o, e);
+}
+
+void FilesystemWidget::receivedStderr(KProcess *, char *buffer, int length)
+{
+ m_stderrString.setLatin1(buffer, length);
+}
+
+void FilesystemWidget::processExited(KProcess *)
+{
+ delete m_process;
+ m_process = 0;
+ kdDebug(2003) << "Deleting KProcess pointer" << endl;
+
+ if (m_stderrString.isEmpty())
+ return;
+
+ QStringList errorList = QStringList::split("\n", m_stderrString);
+ QString message = i18n("<qt>The following errors occurred:<ul>");
+
+ QStringList::Iterator it;
+ for (it = errorList.begin(); it != errorList.end(); ++it) {
+ message += QString::fromLatin1("<li>%1</li>")
+ .arg((*it).replace(QRegExp("[u]?mount: "), QString::null));
+ }
+
+ message += QString::fromLatin1("</ul></qt>");
+ KMessageBox::sorry(0, message);
+}
+
+void FilesystemWidget::createProcess(const QString &command, const QString &point)
+{
+ m_process = new KProcess();
+ connect(m_process,
+ SIGNAL(receivedStderr(KProcess *, char *, int)),
+ SLOT(receivedStderr(KProcess *, char *, int)));
+ connect(m_process,
+ SIGNAL(processExited(KProcess *)),
+ SLOT(processExited(KProcess *)));
+
+ (*m_process) << command << point;
+ void(m_process->start(KProcess::NotifyOnExit, KProcess::Stderr));
+}
+
+void FilesystemWidget::showMenu(uint id)
+{
+ if (id > m_list.count())
+ return;
+
+ QPopupMenu menu;
+ menu.insertItem(SmallIcon("hdd_mount"), i18n("&Mount Device"), 1);
+ menu.insertItem(SmallIcon("hdd_unmount"), i18n("&Unmount Device"), 2);
+
+ switch (menu.exec(QCursor::pos())) {
+ case 1:
+ createProcess("mount", m_list.at(id)->mountPoint());
+ break;
+ case 2:
+ createProcess("umount", m_list.at(id)->mountPoint());
+ break;
+ }
+}
+
+#include "filesystemwidget.moc"
diff --git a/ksim/monitors/filesystem/filesystemwidget.h b/ksim/monitors/filesystem/filesystemwidget.h
new file mode 100644
index 0000000..d169b9a
--- /dev/null
+++ b/ksim/monitors/filesystem/filesystemwidget.h
@@ -0,0 +1,78 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef FSYSTEM_WIDGET_H
+#define FSYSTEM_WIDGET_H
+
+#include <progress.h>
+
+#include <qptrlist.h>
+
+class KProcess;
+class QVBoxLayout;
+
+class FilesystemWidget : public QWidget
+{
+ Q_OBJECT
+ public:
+ FilesystemWidget(QWidget *parent, const char *name);
+ ~FilesystemWidget();
+
+ void append(int, const QString &);
+ void setText(uint, const QString &);
+ void setValue(uint, int);
+ void clear();
+
+ protected:
+ bool eventFilter(QObject *, QEvent *);
+
+ private slots:
+ void receivedStderr(KProcess *, char *, int);
+ void processExited(KProcess *);
+
+ private:
+ class Filesystem
+ {
+ public:
+ Filesystem();
+ Filesystem(KSim::Progress *, const QString &);
+ ~Filesystem();
+
+ KSim::Progress *display() const;
+ const QString &mountPoint() const;
+ const QString &text() const;
+ int value() const;
+
+ void setText(const QString &);
+ void setValue(int);
+
+ QString m_mountPoint;
+ KSim::Progress *m_display;
+ };
+
+ void createProcess(const QString &, const QString &);
+ void showMenu(uint);
+
+ typedef QPtrList<Filesystem> ProgressList;
+ ProgressList m_list;
+ QVBoxLayout *m_layout;
+ KProcess *m_process;
+ QString m_stderrString;
+};
+#endif
diff --git a/ksim/monitors/filesystem/fsystemconfig.cpp b/ksim/monitors/filesystem/fsystemconfig.cpp
new file mode 100644
index 0000000..9b07ee4
--- /dev/null
+++ b/ksim/monitors/filesystem/fsystemconfig.cpp
@@ -0,0 +1,184 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "fsystemconfig.h"
+#include "fsystemconfig.moc"
+
+#include <kconfig.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <klistview.h>
+#include <kapplication.h>
+#include <knuminput.h>
+#include <kdebug.h>
+
+#include <qcheckbox.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qlabel.h>
+#include <qwhatsthis.h>
+
+class FSysViewItem : public QCheckListItem
+{
+ public:
+ FSysViewItem(QListView *parent, const QString &text1,
+ const QString &text2, const QString &text3)
+ : QCheckListItem(parent, text1, CheckBox)
+ {
+ setText(1, text2);
+ setText(2, text3);
+ }
+};
+
+FsystemConfig::FsystemConfig(KSim::PluginObject *parent, const char *name)
+ : KSim::PluginPage(parent, name)
+{
+ m_mainLayout = new QGridLayout(this);
+ m_mainLayout->setSpacing(6);
+
+ m_availableMounts = new KListView(this);
+ m_availableMounts->addColumn(i18n("Mounted Partition"));
+ m_availableMounts->addColumn(i18n("Device"));
+ m_availableMounts->addColumn(i18n("Type"));
+ m_mainLayout->addMultiCellWidget(m_availableMounts, 0, 0, 0, 3);
+
+ m_showPercentage = new QCheckBox(this);
+ m_showPercentage->setText(i18n("Show percentage"));
+ m_mainLayout->addMultiCellWidget(m_showPercentage, 1, 1, 0, 3);
+
+ m_splitNames = new QCheckBox(this);
+ m_splitNames->setText(i18n("Display short mount point names"));
+ QWhatsThis::add(m_splitNames, i18n("This option shortens the text"
+ " to shrink down a mount point. E.G: a mount point /home/myuser"
+ " would become myuser."));
+ m_mainLayout->addMultiCellWidget(m_splitNames, 2, 2, 0, 3);
+
+ m_intervalLabel = new QLabel(this);
+ m_intervalLabel->setText( i18n("Update interval:"));
+ m_intervalLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
+ QSizePolicy::Fixed));
+ m_mainLayout->addMultiCellWidget(m_intervalLabel, 3, 3, 0, 0);
+
+ m_updateTimer = new KIntSpinBox(this);
+ m_updateTimer->setValue(60);
+ QToolTip::add(m_updateTimer, i18n("0 means no update"));
+ m_mainLayout->addMultiCellWidget(m_updateTimer, 3, 3, 1, 1);
+
+ QLabel *intervalLabel = new QLabel(this);
+ intervalLabel->setText(i18n("seconds"));
+ intervalLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
+ QSizePolicy::Fixed));
+ m_mainLayout->addMultiCellWidget(intervalLabel, 3, 3, 2, 2);
+
+ m_entries = FilesystemStats::readEntries();
+ getStats();
+}
+
+FsystemConfig::~FsystemConfig()
+{
+}
+
+void FsystemConfig::readConfig()
+{
+ config()->setGroup("Fsystem");
+ m_showPercentage->setChecked(config()->readBoolEntry("ShowPercentage", true));
+ m_updateTimer->setValue(config()->readNumEntry("updateValue", 60));
+ m_splitNames->setChecked(config()->readBoolEntry("ShortenEntries", false));
+
+ if (!m_availableMounts->childCount())
+ return;
+
+ QStringList list = config()->readListEntry("mountEntries");
+ for (QListViewItemIterator it(m_availableMounts); it.current(); ++it) {
+ QString string = it.current()->text(0) + ":" + splitString(it.current()->text(0));
+ static_cast<QCheckListItem *>(it.current())->setOn(list.contains(string) > 0);
+ }
+}
+
+void FsystemConfig::saveConfig()
+{
+ config()->setGroup("Fsystem");
+ config()->writeEntry("ShowPercentage", m_showPercentage->isChecked());
+ config()->writeEntry("updateValue", m_updateTimer->value());
+ config()->writeEntry("ShortenEntries", m_splitNames->isChecked());
+
+ QStringList list;
+ for (QListViewItemIterator it(m_availableMounts); it.current(); ++it) {
+ if (static_cast<QCheckListItem *>(it.current())->isOn())
+ list.append(it.current()->text(0) + ":" + splitString(it.current()->text(0)));
+ }
+
+ config()->writeEntry("mountEntries", list);
+}
+
+void FsystemConfig::showEvent(QShowEvent *)
+{
+ // FIXME: Maybe this is the slow method of doing this?
+ // Eitherway, i need to find a way to only update the list
+ // if the amount of mounted partitions has changed
+ FilesystemStats::List entries = FilesystemStats::readEntries();
+ if ( entries.count() == m_entries.count() )
+ return;
+
+ m_entries = entries;
+
+ // Update the entries to take into account
+ // any mounted/unmounted filesystems
+ m_availableMounts->clear();
+ getStats();
+}
+
+void FsystemConfig::getStats()
+{
+ int total = 0;
+ int free = 0;
+
+ FilesystemStats::List::ConstIterator it;
+ for ( it = m_entries.begin(); it != m_entries.end(); ++it )
+ {
+ if ( !FilesystemStats::readStats( ( *it ).dir, total, free ) )
+ continue;
+
+ if ( !m_availableMounts->findItem( ( *it ).dir, 0 ) )
+ {
+ (void) new FSysViewItem( m_availableMounts, ( *it ).dir,
+ ( *it ).fsname, ( *it ).type );
+ }
+ }
+
+ if (!m_availableMounts->childCount())
+ return;
+
+ config()->setGroup("Fsystem");
+ QStringList list = config()->readListEntry("mountEntries");
+ for (QListViewItemIterator it(m_availableMounts); it.current(); ++it) {
+ QString string = it.current()->text(0) + ":" + splitString(it.current()->text(0));
+ static_cast<QCheckListItem *>(it.current())->setOn(list.contains(string) > 0);
+ }
+}
+
+QString FsystemConfig::splitString(const QString &string) const
+{
+ if (string == "/" || !m_splitNames->isChecked())
+ return string;
+
+ int location = string.findRev("/");
+ QString newString(string);
+ return newString.remove(0, location + 1);
+}
diff --git a/ksim/monitors/filesystem/fsystemconfig.h b/ksim/monitors/filesystem/fsystemconfig.h
new file mode 100644
index 0000000..353dcf8
--- /dev/null
+++ b/ksim/monitors/filesystem/fsystemconfig.h
@@ -0,0 +1,58 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef FSYSTEMCONFIG_H
+#define FSYSTEMCONFIG_H
+
+#include <pluginmodule.h>
+#include "filesystemstats.h"
+
+class KIntSpinBox;
+class KListView;
+class QGridLayout;
+class QCheckBox;
+class QLabel;
+class QListBoxItem;
+
+class FsystemConfig : public KSim::PluginPage
+{
+ Q_OBJECT
+ public:
+ FsystemConfig(KSim::PluginObject *parent, const char *name);
+ ~FsystemConfig();
+
+ virtual void saveConfig();
+ virtual void readConfig();
+
+ protected:
+ void showEvent(QShowEvent *);
+
+ private:
+ void getStats();
+ QString splitString(const QString &string) const;
+
+ QCheckBox *m_showPercentage;
+ QCheckBox *m_splitNames;
+ QLabel *m_intervalLabel;
+ KIntSpinBox *m_updateTimer;
+ KListView *m_availableMounts;
+ QGridLayout *m_mainLayout;
+ FilesystemStats::List m_entries;
+};
+#endif // FILESYSTEM_H
diff --git a/ksim/monitors/filesystem/fsystemiface.h b/ksim/monitors/filesystem/fsystemiface.h
new file mode 100644
index 0000000..d590776
--- /dev/null
+++ b/ksim/monitors/filesystem/fsystemiface.h
@@ -0,0 +1,32 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 - 2004 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef FSYSTEMIFACE_H
+#define FSYSTEMIFACE_H
+
+#include <dcopobject.h>
+
+class FsystemIface : virtual public DCOPObject
+{
+ K_DCOP
+ k_dcop:
+ virtual int totalFreeSpace() const = 0;
+};
+
+#endif // FSYSTEMIFACE_H
diff --git a/ksim/monitors/filesystem/ksimfsystem.cpp b/ksim/monitors/filesystem/ksimfsystem.cpp
new file mode 100644
index 0000000..3303f6d
--- /dev/null
+++ b/ksim/monitors/filesystem/ksimfsystem.cpp
@@ -0,0 +1,202 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * $Id$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <config.h>
+
+#include <qlayout.h>
+#include <qvaluelist.h>
+#include <qtimer.h>
+#include <qfile.h>
+#include <qregexp.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kaboutapplication.h>
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kconfig.h>
+
+#include "ksimfsystem.h"
+#include "fsystemconfig.h"
+#include "filesystemwidget.h"
+#include "filesystemstats.h"
+#include <themeloader.h>
+
+KSIM_INIT_PLUGIN(PluginModule)
+
+PluginModule::PluginModule(const char *name)
+ : KSim::PluginObject(name)
+{
+ setConfigFileName(instanceName());
+}
+
+PluginModule::~PluginModule()
+{
+}
+
+KSim::PluginView *PluginModule::createView(const char *className)
+{
+ return new Fsystem(this, className);
+}
+
+KSim::PluginPage *PluginModule::createConfigPage(const char *className)
+{
+ return new FsystemConfig(this, className);
+}
+
+void PluginModule::showAbout()
+{
+ QString version = kapp->aboutData()->version();
+
+ KAboutData aboutData(instanceName(),
+ I18N_NOOP("KSim FileSystem Plugin"), version.latin1(),
+ I18N_NOOP("A filesystem plugin for KSim"),
+ KAboutData::License_GPL, "(C) 2001 Robbie Ward");
+
+ aboutData.addAuthor("Robbie Ward", I18N_NOOP("Author"),
+ "linuxphreak@gmx.co.uk");
+ aboutData.addAuthor("Jason Katz-Brown", I18N_NOOP("Some Fixes"),
+ "jason@katzbrown.com");
+ aboutData.addAuthor("Heitham Omar", I18N_NOOP("FreeBSD ports"),
+ "super_ice@ntlworld.com");
+
+ KAboutApplication(&aboutData).exec();
+}
+
+Fsystem::Fsystem(KSim::PluginObject *parent, const char *name)
+ : DCOPObject("fsystem"),
+ KSim::PluginView(parent, name)
+{
+ config()->setGroup("Fsystem");
+ QVBoxLayout *vbLayout = new QVBoxLayout(this);
+ vbLayout->setAutoAdd(true);
+
+ QSpacerItem *item = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
+ vbLayout->addItem(item);
+
+ m_mountEntries = makeList(config()->readListEntry("mountEntries"));
+ m_showPercentage = config()->readBoolEntry("ShowPercentage", true);
+
+ m_widget = new FilesystemWidget(this, "FilesystemWidget");
+
+ createFreeInfo();
+
+ m_updateTimer = new QTimer(this);
+ connect(m_updateTimer, SIGNAL(timeout()), SLOT(updateFS()));
+ m_updateTimer->start(config()->readNumEntry("updateValue", 60) * 1000);
+}
+
+Fsystem::~Fsystem()
+{
+}
+
+void Fsystem::reparseConfig()
+{
+ config()->setGroup("Fsystem");
+
+ m_showPercentage = config()->readBoolEntry("ShowPercentage", true);
+ MountEntryList mountEntries = makeList(config()->readListEntry("mountEntries"));
+
+ if (m_mountEntries != mountEntries) {
+ m_widget->clear();
+ m_mountEntries = mountEntries;
+ createFreeInfo();
+ }
+
+ updateFS();
+}
+
+int Fsystem::totalFreeSpace() const
+{
+ int totalSize, totalFree;
+ int totalFreeSpace = 0;
+ MountEntryList::ConstIterator it;
+ for (it = m_mountEntries.begin(); it != m_mountEntries.end(); ++it) {
+ if ( FilesystemStats::readStats( ( *it ).first, totalSize, totalFree ) )
+ totalFreeSpace += totalFree;
+ }
+
+ return totalFreeSpace;
+}
+
+void Fsystem::createFreeInfo()
+{
+ int total, free;
+ int i = 0;
+ MountEntryList::ConstIterator it;
+ for (it = m_mountEntries.begin(); it != m_mountEntries.end(); ++it) {
+ // returns the total space and free space from *it
+ // (the current mounted partition)
+ if ( !FilesystemStats::readStats( ( *it ).first, total, free ) )
+ continue;
+
+ int percent = 0;
+ if( total != 0)
+ percent = ((total - free) * 100) / total;
+ m_widget->append(total, (*it).first);
+ m_widget->setValue(i, total - free);
+ if (m_showPercentage)
+ m_widget->setText(i, ((*it).second.isEmpty() ? (*it).first : (*it).second)
+ + " - " + QString::number(percent) + "%");
+ else
+ m_widget->setText(i, ((*it).second.isEmpty() ? (*it).first : (*it).second));
+ i++;
+ }
+}
+
+void Fsystem::updateFS()
+{
+ int total, free;
+ int i = 0;
+ MountEntryList::ConstIterator it;
+ for (it = m_mountEntries.begin(); it != m_mountEntries.end(); ++it) {
+ // returns the total space and free space from *it
+ // (the current mounted partition)
+ if ( !FilesystemStats::readStats( ( *it ).first, total, free ) )
+ continue;
+
+ int percent = 0;
+ if( total != 0 )
+ percent = ((total - free) * 100) / total;
+ m_widget->setValue(i, total - free);
+ if (m_showPercentage)
+ m_widget->setText(i, ((*it).second.isEmpty() ? (*it).first : (*it).second)
+ + " - " + QString::number(percent) + "%");
+ else
+ m_widget->setText(i, ((*it).second.isEmpty() ? (*it).first : (*it).second));
+ i++;
+ }
+}
+
+Fsystem::MountEntryList Fsystem::makeList(const QStringList &list) const
+{
+ MountEntryList newList;
+ QStringList splitList;
+ QStringList::ConstIterator it;
+ for (it = list.begin(); it != list.end(); ++it) {
+ splitList = QStringList::split(":", (*it));
+ newList.append(qMakePair(splitList[0], splitList[1]));
+ }
+
+ return newList;
+}
+
+#include "ksimfsystem.moc"
diff --git a/ksim/monitors/filesystem/ksimfsystem.h b/ksim/monitors/filesystem/ksimfsystem.h
new file mode 100644
index 0000000..c3d403f
--- /dev/null
+++ b/ksim/monitors/filesystem/ksimfsystem.h
@@ -0,0 +1,76 @@
+/* ksim - a system monitor for kde
+ *
+ * Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef FSYSTEM_H
+#define FSYSTEM_H
+
+#include <pluginmodule.h>
+#include "fsystemiface.h"
+
+class KPopupMenu;
+class FilesystemWidget;
+class QTimer;
+
+/**
+ * This class is the filesystem monitor plugin
+ *
+ * @author Robbie Ward <linuxphreak@gmx.co.uk>
+ * @version 0.1
+ */
+class PluginModule : public KSim::PluginObject
+{
+ public:
+ PluginModule(const char *name);
+ ~PluginModule();
+
+ virtual KSim::PluginView *createView(const char *);
+ virtual KSim::PluginPage *createConfigPage(const char *);
+
+ virtual void showAbout();
+};
+
+class Fsystem : public KSim::PluginView, public FsystemIface
+{
+ Q_OBJECT
+ public:
+ /**
+ * construtor of Fsystem, calls all init functions to create the plugin.
+ */
+ Fsystem(KSim::PluginObject *parent, const char *name);
+ ~Fsystem();
+
+ virtual void reparseConfig();
+ int totalFreeSpace() const;
+
+ public slots:
+ void createFreeInfo();
+
+ private slots:
+ void updateFS();
+
+ private:
+ typedef QValueList<QPair<QString, QString> > MountEntryList;
+ MountEntryList makeList(const QStringList &list) const;
+
+ FilesystemWidget *m_widget;
+ QTimer *m_updateTimer;
+ MountEntryList m_mountEntries;
+ bool m_showPercentage;
+};
+#endif