45
45
#include <qlayout.h>
46
46
#include <qgroupbox.h>
47
47
#include <kprocess.h>
48
49
#include <kdebug.h>
50
using namespace MountMan;
52
KMountManGUI::KMountManGUI() : KDialogBase(0,0,true,"Mount.Man"),
53
info(0), mountList(0) {
54
watcher = new KRdirWatch();
56
connect((QObject*)&krMtMan,SIGNAL(updated()),this,SLOT(updateList())); // <>
57
connect(watcher,SIGNAL(dirty()),(QObject*)&krMtMan,SLOT(forceUpdate())); //<>
58
setButtonOKText(i18n("Close"),i18n("Close the Mount.Man window."),0);
59
showButtonApply(false); showButtonCancel(false);
60
setPlainCaption(i18n("MountMan - Your Mount-Manager"));
61
widget=new KJanusWidget(this,0,KJanusWidget::Tabbed);
63
setMainWidget(widget);
64
widget->setMinimumSize(widget->sizeHint().width()+mountList->columnWidth(5),
65
widget->sizeHint().height());
66
setMinimumSize(widget->minimumSize().width(), widget->minimumSize().height());
67
resize(minimumSize());
70
connect(mountList,SIGNAL(doubleClicked(QListViewItem *)),this,
71
SLOT(doubleClicked(QListViewItem*)));
72
connect(mountList,SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)),
73
this, SLOT(clicked(QListViewItem*)));
74
connect(mountList,SIGNAL(clicked(QListViewItem *)), this,
75
SLOT(changeActive(QListViewItem *)));
76
connect(mountList,SIGNAL(selectionChanged(QListViewItem *)), this,
77
SLOT(changeActive(QListViewItem *)));
51
#include <qfileinfo.h>
52
#include <sys/param.h>
54
// use of version of it until kde fixes theirs
55
#include "kdiskfreesp.h"
59
#define MTAB "/etc/mtab"
61
KMountManGUI::KMountManGUI() : KDialogBase( krApp, 0, true, "Mount.Man" ),
62
info( 0 ), mountList( 0 ) {
63
watcher = new QTimer( this );
64
connect( watcher, SIGNAL( timeout() ), this, SLOT( checkMountChange() ) );
66
connect( this, SIGNAL( finishedGettingSpaceData() ), this, SLOT( updateList() ) );
67
setButtonOK( i18n( "&Close" ) );
68
showButtonApply( false ); showButtonCancel( false );
69
setPlainCaption( i18n( "MountMan - Your Mount-Manager" ) );
70
widget = new KJanusWidget( this, 0, KJanusWidget::Tabbed );
72
setMainWidget( widget );
73
widget->setMinimumSize( widget->sizeHint().width() + mountList->columnWidth( 5 ),
74
widget->sizeHint().height() );
75
setMinimumSize( widget->minimumSize().width(), widget->minimumSize().height() );
76
resize( minimumSize() );
79
connect( mountList, SIGNAL( doubleClicked( QListViewItem * ) ), this,
80
SLOT( doubleClicked( QListViewItem* ) ) );
81
connect( mountList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
82
this, SLOT( clicked( QListViewItem* ) ) );
83
connect( mountList, SIGNAL( clicked( QListViewItem * ) ), this,
84
SLOT( changeActive( QListViewItem * ) ) );
85
connect( mountList, SIGNAL( selectionChanged( QListViewItem * ) ), this,
86
SLOT( changeActive( QListViewItem * ) ) );
92
KMountManGUI::~KMountManGUI() {
82
97
void KMountManGUI::createLayout() {
83
mainPage=widget->addPage(i18n("Filesystems"),0);
85
widget->showPage(Filesystems);
98
mainPage = widget->addPage( i18n( "Filesystems" ), 0 );
100
widget->showPage( Filesystems );
88
103
void KMountManGUI::createMainPage() {
89
// check if we need to clean up first!
95
// clean up is finished...
96
QGridLayout *layout=new QGridLayout(mainPage,1,1);
97
mountList=new QListView(mainPage); // create the main container
98
krConfig->setGroup("Look&Feel");
99
mountList->setFont(krConfig->readFontEntry("Filelist Font",_FilelistFont));
100
mountList->setAllColumnsShowFocus(true);
101
mountList->setMultiSelection(false);
102
mountList->setSelectionMode(QListView::Single);
103
mountList->setVScrollBarMode(QScrollView::AlwaysOn);
104
mountList->setHScrollBarMode(QScrollView::Auto);
105
mountList->setShowSortIndicator(true);
106
int i=QFontMetrics(mountList->font()).width("W");
107
int j=QFontMetrics(mountList->font()).width("0");
109
mountList->addColumn(i18n("Name"),j*8);
110
mountList->addColumn(i18n("Type"),j*4);
111
mountList->addColumn(i18n("Mnt.Point"),j*6);
112
mountList->addColumn(i18n("Total Size"),j*6);
113
mountList->addColumn(i18n("Free Size"),j*6);
114
mountList->addColumn(i18n("Free %"),j*5);
115
mountList->setColumnWidthMode(0,QListView::Maximum);
116
mountList->setColumnWidthMode(1,QListView::Maximum);
117
mountList->setColumnWidthMode(2,QListView::Maximum);
118
mountList->setColumnWidthMode(3,QListView::Maximum);
119
mountList->setColumnWidthMode(4,QListView::Maximum);
120
mountList->setColumnWidthMode(5,QListView::Maximum);
121
// now the list is created, time to fill it with data.
122
krMtMan.forceUpdate();
123
QGroupBox *box=new QGroupBox("MountMan.Info",mainPage);
124
box->setAlignment(Qt::AlignHCenter);
125
info=new KRFSDisplay(box);
126
info->resize(info->width(),height());
127
layout->addWidget(box,0,0);
128
layout->addWidget(mountList,0,1);
104
// check if we need to clean up first!
105
if ( mountList != 0 ) {
110
// clean up is finished...
111
QGridLayout *layout = new QGridLayout( mainPage, 1, 1 );
112
mountList = new QListView( mainPage ); // create the main container
113
krConfig->setGroup( "Look&Feel" );
114
mountList->setFont( krConfig->readFontEntry( "Filelist Font", _FilelistFont ) );
115
mountList->setAllColumnsShowFocus( true );
116
mountList->setMultiSelection( false );
117
mountList->setSelectionMode( QListView::Single );
118
mountList->setVScrollBarMode( QScrollView::AlwaysOn );
119
mountList->setHScrollBarMode( QScrollView::Auto );
120
mountList->setShowSortIndicator( true );
121
int i = QFontMetrics( mountList->font() ).width( "W" );
122
int j = QFontMetrics( mountList->font() ).width( "0" );
123
j = ( i > j ? i : j );
124
mountList->addColumn( i18n( "Name" ), j * 8 );
125
mountList->addColumn( i18n( "Type" ), j * 4 );
126
mountList->addColumn( i18n( "Mnt.Point" ), j * 6 );
127
mountList->addColumn( i18n( "Total Size" ), j * 6 );
128
mountList->addColumn( i18n( "Free Size" ), j * 6 );
129
mountList->addColumn( i18n( "Free %" ), j * 5 );
130
mountList->setColumnWidthMode( 0, QListView::Maximum );
131
mountList->setColumnWidthMode( 1, QListView::Maximum );
132
mountList->setColumnWidthMode( 2, QListView::Maximum );
133
mountList->setColumnWidthMode( 3, QListView::Maximum );
134
mountList->setColumnWidthMode( 4, QListView::Maximum );
135
mountList->setColumnWidthMode( 5, QListView::Maximum );
136
// now the list is created, time to fill it with data.
137
//=>krMtMan.forceUpdate();
138
QGroupBox *box = new QGroupBox( "MountMan.Info", mainPage );
139
box->setAlignment( Qt::AlignHCenter );
140
info = new KRFSDisplay( box );
141
info->resize( info->width(), height() );
142
layout->addWidget( box, 0, 0 );
143
layout->addWidget( mountList, 0, 1 );
146
void KMountManGUI::getSpaceData() {
148
lastMtab = QFileInfo(MTAB).lastModified();
150
mounted = KMountPoint::currentMountPoints();
151
possible = KMountPoint::possibleMountPoints();
152
if ( mounted.size() == 0 ) { // nothing is mounted
153
updateList(); // let's continue
157
numOfMountPoints = mounted.size();
158
for ( KMountPoint::List::iterator it = mounted.begin(); it != mounted.end(); ++it ) {
159
// don't bother with invalid file systems
160
if (krMtMan.invalidFilesystem((*it)->mountType())) {
164
KDiskFreeSp *sp = KDiskFreeSp::findUsageInfo( ( *it ) ->mountPoint() );
165
connect( sp, SIGNAL( foundMountPoint( const QString &, unsigned long, unsigned long, unsigned long ) ),
166
this, SLOT( gettingSpaceData( const QString&, unsigned long, unsigned long, unsigned long ) ) );
167
connect( sp, SIGNAL( done() ), this, SLOT( gettingSpaceData() ) );
171
// this decrements the counter, while the following uses the data
172
// used when certain filesystem (/dev, /sys) can't have the needed stats
173
void KMountManGUI::gettingSpaceData() {
174
if ( --numOfMountPoints == 0 ) {
175
emit finishedGettingSpaceData();
179
void KMountManGUI::gettingSpaceData( const QString &mountPoint, unsigned long kBSize,
180
unsigned long kBUsed, unsigned long kBAvail ) {
181
KMountPoint *m = KMountMan::findInListByMntPoint( mounted, mountPoint );
182
if ( !m ) { // this should never never never happen!
183
KMessageBox::error( 0, i18n( "Critical Error" ),
184
i18n( "Internal error in MountMan\nPlease email the developers" ) );
188
data.setMntPoint( mountPoint );
189
data.setMounted( true );
190
data.setTotalBlks( kBSize );
191
data.setFreeBlks( kBAvail );
192
data.setName( m->mountedFrom() );
193
data.setType( m->mountType() );
194
fileSystems.append( data );
197
void KMountManGUI::addItemToMountList( QListView *lst, fsData &fs ) {
198
bool mtd = fs.mounted();
200
QString tSize = QString( "%1" ).arg( KIO::convertSizeFromKB( fs.totalBlks() ) );
201
QString fSize = QString( "%1" ).arg( KIO::convertSizeFromKB( fs.freeBlks() ) );
202
QString sPrct = QString( "%1%" ).arg( 100 - ( fs.usedPerct() ) );
203
QListViewItem *item = new QListViewItem( lst, fs.name(),
204
fs.type(), fs.mntPoint(),
205
( mtd ? tSize : QString( "N/A" ) ), ( mtd ? fSize : QString( "N/A" ) ),
206
( mtd ? sPrct : QString( "N/A" ) ) );
208
QString id = fs.name().left(7); // only works assuming devices start with "/dev/XX"
210
if ( id == "/dev/fd") {
211
icon = new QPixmap( LOADICON( mtd ? "3floppy_mount" : "3floppy_unmount" ) );
212
} else if ( id == "/dev/cd" || fs.type() == "iso9660" ) {
213
icon = new QPixmap( LOADICON( mtd ? "cdrom_mount" : "cdrom_unmount" ) );
214
} else if ( fs.type() == "nfs" || fs.type() == "smbfs" ) {
215
icon = new QPixmap( LOADICON( mtd ? "nfs_mount" : "nfs_unmount" ) );
216
} else icon = new QPixmap( LOADICON( mtd ? "hdd_mount" : "hdd_unmount" ) );
218
item->setPixmap( 0, *icon );
131
222
void KMountManGUI::updateList() {
135
for (it=krMtMan.filesystems.first(); it!=0 ; it=krMtMan.filesystems.next()) {
136
bool mtd=it->mounted();
137
QString tSize=QString("%1").arg(KIO::convertSizeFromKB(it->totalBlks()));
138
QString fSize=QString("%1").arg(KIO::convertSizeFromKB(it->freeBlks()));
139
QString sPrct=QString("%1%").arg(100-(it->usedPerct()));
140
QListViewItem *item=new QListViewItem(mountList,it->name(),
141
it->type(),it->mntPoint(),
142
(mtd ? tSize : QString("N/A")),(mtd ? fSize : QString("N/A")),
143
(mtd ? sPrct : QString("N/A")));
144
QString id=krMtMan.followLink(it->name()).left(2);
146
if (id=="fd" || krMtMan.followLink(it->name())=="floppy")
147
icon=new QPixmap(LOADICON(mtd ? "3floppy_mount" : "3floppy_unmount"));
149
if (id=="cd" || it->type()=="iso9660") icon=new QPixmap(LOADICON(mtd ? "cdrom_mount" : "cdrom_unmount"));
151
if (it->type()=="nfs" || it->type()=="smbfs")
152
icon=new QPixmap(LOADICON(mtd ? "nfs_mount" : "nfs_unmount"));
154
if (id=="hd") icon=new QPixmap(LOADICON(mtd ? "hdd_mount" : "hdd_unmount"));
156
icon=new QPixmap(LOADICON(mtd ? "hdd_mount" : "hdd_unmount")); // our default
158
item->setPixmap(0,*icon);
161
mountList->clearSelection();
163
info->setEmpty(true);
166
watcher->startScan();
169
void KMountManGUI::createDirwatch() {
171
for (it=krMtMan.filesystems.first(); it!=0 ; it=krMtMan.filesystems.next()) {
172
watcher->addDir(it->mntPoint());
176
void KMountManGUI::doubleClicked(QListViewItem *i) {
178
// change the active panel to this mountpoint
179
fsData *system=krMtMan.location(i->text(0));
180
connect((QObject*)this,SIGNAL(refreshPanel(QString)), (QObject*)SLOTS,
181
SLOT(refresh(QString)));
182
emit refreshPanel(system->mntPoint());
183
disconnect(this,SIGNAL(refreshPanel(QString)),0,0);
224
// this handles the mounted ones
225
for ( QValueList<fsData>::iterator it = fileSystems.begin(); it != fileSystems.end() ; ++it ) {
226
if (krMtMan.invalidFilesystem((*it).type())) {
229
addItemToMountList( mountList, *it );
232
// now, handle the non-mounted ones
233
for (KMountPoint::List::iterator it = possible.begin(); it != possible.end(); ++it) {
234
// make sure we don't add things we've already added
235
if (KMountMan::findInListByMntPoint(mounted, (*it)->mountPoint())) {
239
data.setMntPoint((*it)->mountPoint());
240
data.setMounted(false);
241
data.setType((*it)->mountType());
242
data.setName((*it)->mountedFrom());
243
fileSystems.append(data);
245
if (krMtMan.invalidFilesystem(data.type())) continue;
246
addItemToMountList(mountList, data);
250
mountList->clearSelection();
252
info->setEmpty( true );
255
watcher->start( WATCHER_DELAY, true ); // starting the watch timer ( single shot )
258
void KMountManGUI::checkMountChange() {
259
if (QFileInfo(MTAB).lastModified() != lastMtab)
261
watcher->start( WATCHER_DELAY, true ); // starting the watch timer ( single shot )
264
void KMountManGUI::doubleClicked( QListViewItem *i ) {
266
return; // we don't want to refresh to swap, do we ?
268
// change the active panel to this mountpoint
269
connect( ( QObject* ) this, SIGNAL( refreshPanel( const KURL & ) ), ( QObject* ) SLOTS,
270
SLOT( refresh( const KURL & ) ) );
271
emit refreshPanel( vfs::fromPathOrURL( i->text(2) ) ); // text(2) ? so ugly ...
272
disconnect( this, SIGNAL( refreshPanel( const KURL & ) ), 0, 0 );
187
276
// when user clicks on a filesystem, change information
188
void KMountManGUI::changeActive(QListViewItem *i) {
190
fsData *system=krMtMan.location(i->text(0));
191
info->setAlias(system->mntPoint());
192
info->setRealName(system->name());
193
info->setMounted(system->mounted());
194
info->setEmpty(false);
195
info->setTotalSpace(system->totalBlks());
196
info->setFreeSpace(system->freeBlks());
197
info->setSupermount(system->supermount);
277
void KMountManGUI::changeActive( QListViewItem *i ) {
281
for (QValueList<fsData>::Iterator it = fileSystems.begin(); it != fileSystems.end(); ++it) {
282
// the only thing which is unique is the mount point
283
if ((*it).mntPoint() == i->text(2)) { // text(2) ? ugly ugly ugly
290
KMessageBox::error(0, i18n("Critical Error"), i18n("Internal error in MountMan\nCall the developers"));
293
info->setAlias( system->mntPoint() );
294
info->setRealName( system->name() );
295
info->setMounted( system->mounted() );
296
info->setEmpty( false );
297
info->setTotalSpace( system->totalBlks() );
298
info->setFreeSpace( system->freeBlks() );
201
302
// called when right-clicked on a filesystem
202
void KMountManGUI::clicked(QListViewItem *item) {
203
// these are the values that will exist in the menu
205
#define UNMOUNT_ID 91
208
//////////////////////////////////////////////////////////
210
fsData *system=krMtMan.location(item->text(0));
212
KMessageBox::error(0, i18n("MountMan has an internal error.\nPlease notify the developers.\nThank you."));
217
popup.insertTitle(i18n("MountMan"));
218
if (!system->mounted())
219
popup.insertItem(i18n("Mount"),MOUNT_ID);
220
else popup.insertItem(i18n("Unmount"),UNMOUNT_ID);
221
if (krMtMan.ejectable(system->mntPoint()))
222
// if (system->type()=="iso9660" || krMtMan.followLink(system->name()).left(2)=="cd")
223
popup.insertItem(i18n("Eject"),EJECT_ID);
225
popup.insertItem(i18n("Format"),FORMAT_ID);
226
popup.setItemEnabled(FORMAT_ID,false);
303
void KMountManGUI::clicked( QListViewItem *item ) {
304
// these are the values that will exist in the menu
306
#define UNMOUNT_ID 91
309
//////////////////////////////////////////////////////////
310
if ( !item ) return ;
313
for (QValueList<fsData>::Iterator it = fileSystems.begin(); it != fileSystems.end(); ++it) {
314
// the only thing which is unique is the mount point
315
if ((*it).mntPoint() == item->text(2)) { // text(2) ? ugly ugly ugly
322
KMessageBox::error( 0, i18n( "MountMan has an internal error. Please notify the developers. Thank you." ) );
327
popup.insertTitle( i18n( "MountMan" ) );
328
if ( !system->mounted() ) {
329
popup.insertItem( i18n( "Mount" ), MOUNT_ID );
330
bool enable = !(krMtMan.nonmountFilesystem(system->type(), system->mntPoint()));
331
popup.setItemEnabled( MOUNT_ID, enable);
333
popup.insertItem( i18n( "Unmount" ), UNMOUNT_ID );
334
bool enable = !(krMtMan.nonmountFilesystem(system->type(), system->mntPoint()));
335
popup.setItemEnabled( UNMOUNT_ID, enable);
337
if ( krMtMan.ejectable( system->mntPoint() ) )
338
// if (system->type()=="iso9660" || krMtMan.followLink(system->name()).left(2)=="cd")
339
popup.insertItem( i18n( "Eject" ), EJECT_ID );
341
popup.insertItem( i18n( "Format" ), FORMAT_ID );
342
popup.setItemEnabled( FORMAT_ID, false );
229
int result=popup.exec(QCursor::pos());
230
// check out the user's option
232
case -1 : return; // the user clicked outside of the menu
235
krMtMan.toggleMount(system->name());
240
KMountMan::eject(system->mntPoint());
345
int result = popup.exec( QCursor::pos() );
346
// check out the user's option
348
case - 1 : return ; // the user clicked outside of the menu
351
krMtMan.toggleMount( system->mntPoint() );
356
KMountMan::eject( system->mntPoint() );
245
361
#include "kmountmangui.moc"