1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/* ksim - a system monitor for kde
*
* Copyright (C) 2001 Robbie Ward <[email protected]>
*
* $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 <tqlayout.h>
#include <tqvaluelist.h>
#include <tqtimer.h>
#include <tqfile.h>
#include <tqregexp.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()
{
TQString 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"),
"[email protected]");
aboutData.addAuthor("Jason Katz-Brown", I18N_NOOP("Some Fixes"),
"[email protected]");
aboutData.addAuthor("Heitham Omar", I18N_NOOP("FreeBSD ports"),
"[email protected]");
KAboutApplication(&aboutData).exec();
}
Fsystem::Fsystem(KSim::PluginObject *parent, const char *name)
: DCOPObject("fsystem"),
KSim::PluginView(parent, name)
{
config()->setGroup("Fsystem");
TQVBoxLayout *vbLayout = new TQVBoxLayout(this);
vbLayout->setAutoAdd(true);
TQSpacerItem *item = new TQSpacerItem(0, 0, TQSizePolicy::Expanding, TQSizePolicy::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 TQTimer(this);
connect(m_updateTimer, TQT_SIGNAL(timeout()), TQT_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)
+ " - " + TQString::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)
+ " - " + TQString::number(percent) + "%");
else
m_widget->setText(i, ((*it).second.isEmpty() ? (*it).first : (*it).second));
i++;
}
}
Fsystem::MountEntryList Fsystem::makeList(const TQStringList &list) const
{
MountEntryList newList;
TQStringList splitList;
TQStringList::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it) {
splitList = TQStringList::split(":", (*it));
newList.append(tqMakePair(splitList[0], splitList[1]));
}
return newList;
}
#include "ksimfsystem.moc"
|