~ubuntu-branches/ubuntu/hardy/krusader/hardy

« back to all changes in this revision

Viewing changes to krusader/MountMan/kmountmangui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Angel Ramos
  • Date: 2004-12-30 16:18:26 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041230161826-wx99gkdypyalazpv
Tags: 1.51-1
* New upstream release (Closes: #280037, #287015).
* Moved from section utils to kde (Closes: #286748).
* Renamed dk.po to da.po (Closes: #269414).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
                                kmountmangui.cpp
3
 
                             -------------------
4
 
    copyright            : (C) 2000 by Shie Erlich & Rafi Yanai
5
 
    e-mail               : krusader@users.sourceforge.net
6
 
    web site             : http://krusader.sourceforge.net
7
 
 ---------------------------------------------------------------------------
8
 
  Description 
9
 
 ***************************************************************************
10
 
 
11
 
  A 
12
 
 
13
 
     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
14
 
     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
15
 
     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
16
 
     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
17
 
     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
18
 
     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD
19
 
 
20
 
                                                     S o u r c e    F i l e
21
 
 
22
 
 ***************************************************************************
23
 
 *                                                                         *
24
 
 *   This program is free software; you can redistribute it and/or modify  *
25
 
 *   it under the terms of the GNU General Public License as published by  *
26
 
 *   the Free Software Foundation; either version 2 of the License, or     *
27
 
 *   (at your option) any later version.                                   *
28
 
 *                                                                         *
29
 
 ***************************************************************************/
 
2
                              kmountmangui.cpp
 
3
                           -------------------
 
4
  copyright            : (C) 2000 by Shie Erlich & Rafi Yanai
 
5
  e-mail               : krusader@users.sourceforge.net
 
6
  web site             : http://krusader.sourceforge.net
 
7
---------------------------------------------------------------------------
 
8
Description 
 
9
***************************************************************************
 
10
 
 
11
 
12
 
 
13
   db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
 
14
   88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
 
15
   88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
 
16
   88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
 
17
   88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
 
18
   YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD
 
19
 
 
20
                                                   S o u r c e    F i l e
 
21
 
 
22
***************************************************************************
 
23
*                                                                         *
 
24
*   This program is free software; you can redistribute it and/or modify  *
 
25
*   it under the terms of the GNU General Public License as published by  *
 
26
*   the Free Software Foundation; either version 2 of the License, or     *
 
27
*   (at your option) any later version.                                   *
 
28
*                                                                         *
 
29
***************************************************************************/
30
30
 
31
31
 
32
32
 
35
35
#include "../krusader.h"
36
36
#include "../Dialogs/krspecialwidgets.h"
37
37
#include "../kicons.h"
38
 
#include "../VFS/krdirwatch.h"
39
38
#include "../defaults.h"
 
39
#include "../VFS/vfs.h"
40
40
#include <klocale.h>
41
41
#include <qpixmap.h>
42
42
#include <kpopupmenu.h>
45
45
#include <qlayout.h>
46
46
#include <qgroupbox.h>
47
47
#include <kprocess.h>
 
48
#include <qcursor.h>
48
49
#include <kdebug.h>
49
 
 
50
 
using namespace MountMan;
51
 
 
52
 
KMountManGUI::KMountManGUI() : KDialogBase(0,0,true,"Mount.Man"),
53
 
      info(0), mountList(0) {
54
 
  watcher = new KRdirWatch();
55
 
 
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);
62
 
  createLayout();
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());
68
 
 
69
 
  // connections
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 *)));
78
 
 
79
 
  exec();
 
50
#include <kguiitem.h>
 
51
#include <qfileinfo.h>
 
52
#include <sys/param.h>
 
53
 
 
54
// use of version of it until kde fixes theirs
 
55
#include "kdiskfreesp.h"
 
56
 
 
57
 
 
58
 
 
59
#define MTAB    "/etc/mtab"
 
60
 
 
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() ) );
 
65
 
 
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 );
 
71
   createLayout();
 
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() );
 
77
 
 
78
   // connections
 
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 * ) ) );
 
87
 
 
88
   getSpaceData();
 
89
   exec();
 
90
}
 
91
 
 
92
KMountManGUI::~KMountManGUI() {
 
93
   watcher->stop();
 
94
   delete watcher;
80
95
}
81
96
 
82
97
void KMountManGUI::createLayout() {
83
 
  mainPage=widget->addPage(i18n("Filesystems"),0);
84
 
  createMainPage();
85
 
  widget->showPage(Filesystems);
 
98
   mainPage = widget->addPage( i18n( "Filesystems" ), 0 );
 
99
   createMainPage();
 
100
   widget->showPage( Filesystems );
86
101
}
87
102
 
88
103
void KMountManGUI::createMainPage() {
89
 
  // check if we need to clean up first!
90
 
  if (mountList!=0) {
91
 
    mountList->hide();
92
 
    delete mountList;
93
 
    mountList=0;
94
 
  }
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");
108
 
        j=(i>j ? i : j);
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 ) {
 
106
      mountList->hide();
 
107
      delete mountList;
 
108
      mountList = 0;
 
109
   }
 
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 );
 
144
}
 
145
 
 
146
void KMountManGUI::getSpaceData() {
 
147
   fileSystems.clear();
 
148
        lastMtab = QFileInfo(MTAB).lastModified();
 
149
        
 
150
   mounted = KMountPoint::currentMountPoints();
 
151
        possible = KMountPoint::possibleMountPoints();
 
152
   if ( mounted.size() == 0 ) { // nothing is mounted
 
153
      updateList(); // let's continue
 
154
      return ;
 
155
   }
 
156
 
 
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())) {
 
161
                        --numOfMountPoints;
 
162
                        continue;
 
163
                }
 
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() ) );
 
168
   }
 
169
}
 
170
 
 
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();
 
176
   }
 
177
}
 
178
 
 
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" ) );
 
185
      exit( 1 );
 
186
   }
 
187
   fsData data;
 
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 );
 
195
}
 
196
 
 
197
void KMountManGUI::addItemToMountList( QListView *lst, fsData &fs ) {
 
198
   bool mtd = fs.mounted();
 
199
 
 
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" ) ) );
 
207
   
 
208
        QString id = fs.name().left(7); // only works assuming devices start with  "/dev/XX"
 
209
   QPixmap *icon = 0;
 
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" ) );
 
217
 
 
218
   item->setPixmap( 0, *icon );
 
219
   delete icon;
129
220
}
130
221
 
131
222
void KMountManGUI::updateList() {
132
 
  createDirwatch();
133
 
  fsData *it;
134
 
  mountList->clear();
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);
145
 
                QPixmap *icon=0;
146
 
                if (id=="fd" || krMtMan.followLink(it->name())=="floppy")
147
 
                  icon=new QPixmap(LOADICON(mtd ? "3floppy_mount" : "3floppy_unmount"));
148
 
                else
149
 
                if (id=="cd" || it->type()=="iso9660") icon=new QPixmap(LOADICON(mtd ? "cdrom_mount" : "cdrom_unmount"));
150
 
                else
151
 
                if (it->type()=="nfs" || it->type()=="smbfs")
152
 
                  icon=new QPixmap(LOADICON(mtd ? "nfs_mount" : "nfs_unmount"));
153
 
    else                
154
 
                if (id=="hd") icon=new QPixmap(LOADICON(mtd ? "hdd_mount" : "hdd_unmount"));
155
 
                else
156
 
                icon=new QPixmap(LOADICON(mtd ? "hdd_mount" : "hdd_unmount"));    // our default
157
 
                
158
 
    item->setPixmap(0,*icon);
159
 
    delete icon;
160
 
  }
161
 
  mountList->clearSelection();
162
 
  if (info) {
163
 
    info->setEmpty(true);
164
 
    info->repaint();
165
 
  }
166
 
  watcher->startScan();
167
 
}
168
 
 
169
 
void KMountManGUI::createDirwatch() {
170
 
  fsData* it;
171
 
  for (it=krMtMan.filesystems.first(); it!=0 ; it=krMtMan.filesystems.next()) {
172
 
    watcher->addDir(it->mntPoint());
173
 
  }
174
 
}
175
 
 
176
 
void KMountManGUI::doubleClicked(QListViewItem *i) {
177
 
  if (!i) return;
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);
184
 
  slotClose();
 
223
   mountList->clear();
 
224
   // this handles the mounted ones
 
225
        for ( QValueList<fsData>::iterator it = fileSystems.begin(); it != fileSystems.end() ; ++it ) {
 
226
                if (krMtMan.invalidFilesystem((*it).type())) {
 
227
                        continue;
 
228
                }
 
229
      addItemToMountList( mountList, *it );
 
230
   }
 
231
        
 
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())) {
 
236
                        continue;
 
237
                } else {
 
238
                        fsData data;
 
239
                        data.setMntPoint((*it)->mountPoint());
 
240
                        data.setMounted(false);
 
241
                        data.setType((*it)->mountType());
 
242
                        data.setName((*it)->mountedFrom());
 
243
                        fileSystems.append(data);
 
244
                        
 
245
                        if (krMtMan.invalidFilesystem(data.type())) continue;
 
246
                        addItemToMountList(mountList, data);
 
247
                }
 
248
        }
 
249
        
 
250
   mountList->clearSelection();
 
251
   if ( info ) {
 
252
      info->setEmpty( true );
 
253
      info->repaint();
 
254
   }
 
255
   watcher->start( WATCHER_DELAY, true );   // starting the watch timer ( single shot )
 
256
}
 
257
 
 
258
void KMountManGUI::checkMountChange() {
 
259
        if (QFileInfo(MTAB).lastModified() != lastMtab)
 
260
                getSpaceData();
 
261
   watcher->start( WATCHER_DELAY, true );   // starting the watch timer ( single shot )
 
262
}
 
263
 
 
264
void KMountManGUI::doubleClicked( QListViewItem *i ) {
 
265
   if ( !i )
 
266
                return; // we don't want to refresh to swap, do we ?
 
267
                 
 
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 );
 
273
   slotClose();
185
274
}
186
275
 
187
276
// when user clicks on a filesystem, change information
188
 
void KMountManGUI::changeActive(QListViewItem *i) {
189
 
  if (!i) return;
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);
198
 
  info->repaint();
 
277
void KMountManGUI::changeActive( QListViewItem *i ) {
 
278
        if ( !i ) return ;
 
279
   fsData *system = 0;
 
280
        
 
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
 
284
                        system = &(*it);
 
285
                        break;
 
286
                }
 
287
        }
 
288
        
 
289
        if (system == 0) {
 
290
                KMessageBox::error(0, i18n("Critical Error"), i18n("Internal error in MountMan\nCall the developers"));
 
291
                exit(1);
 
292
        }
 
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() );
 
299
   info->repaint();
199
300
}
200
301
 
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
204
 
  #define MOUNT_ID       90
205
 
  #define UNMOUNT_ID     91
206
 
  #define FORMAT_ID      93
207
 
  #define EJECT_ID       94
208
 
  //////////////////////////////////////////////////////////
209
 
  if (!item) return;
210
 
  fsData *system=krMtMan.location(item->text(0));
211
 
  if (!system) {
212
 
    KMessageBox::error(0, i18n("MountMan has an internal error.\nPlease notify the developers.\nThank you."));
213
 
    exit(0);
214
 
  }
215
 
  // create the menu
216
 
  KPopupMenu popup;
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);
224
 
  else {
225
 
    popup.insertItem(i18n("Format"),FORMAT_ID);
226
 
    popup.setItemEnabled(FORMAT_ID,false);
227
 
  }
 
303
void KMountManGUI::clicked( QListViewItem *item ) {
 
304
   // these are the values that will exist in the menu
 
305
#define MOUNT_ID       90
 
306
#define UNMOUNT_ID     91
 
307
#define FORMAT_ID      93
 
308
#define EJECT_ID       94
 
309
   //////////////////////////////////////////////////////////
 
310
        if ( !item ) return ;
 
311
        
 
312
        fsData *system = 0;
 
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
 
316
                        system = &(*it);
 
317
                        break;
 
318
                }
 
319
        }
 
320
        
 
321
   if ( !system ) {
 
322
      KMessageBox::error( 0, i18n( "MountMan has an internal error. Please notify the developers. Thank you." ) );
 
323
      exit( 0 );
 
324
   }
 
325
   // create the menu
 
326
   KPopupMenu popup;
 
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);
 
332
        } else {
 
333
                popup.insertItem( i18n( "Unmount" ), UNMOUNT_ID );
 
334
                bool enable = !(krMtMan.nonmountFilesystem(system->type(), system->mntPoint()));
 
335
                popup.setItemEnabled( UNMOUNT_ID, enable);
 
336
        }
 
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 );
 
340
   else {
 
341
      popup.insertItem( i18n( "Format" ), FORMAT_ID );
 
342
      popup.setItemEnabled( FORMAT_ID, false );
 
343
   }
228
344
 
229
 
  int result=popup.exec(QCursor::pos());
230
 
  // check out the user's option
231
 
  switch (result) {
232
 
    case -1 : return;     // the user clicked outside of the menu
233
 
    case MOUNT_ID   :
234
 
    case UNMOUNT_ID :
235
 
      krMtMan.toggleMount(system->name());
236
 
      break;
237
 
    case FORMAT_ID :
238
 
      break;
239
 
    case EJECT_ID :
240
 
      KMountMan::eject(system->mntPoint());
241
 
      break;
242
 
  }
 
345
   int result = popup.exec( QCursor::pos() );
 
346
   // check out the user's option
 
347
   switch ( result ) {
 
348
         case - 1 : return ;     // the user clicked outside of the menu
 
349
         case MOUNT_ID :
 
350
         case UNMOUNT_ID :
 
351
         krMtMan.toggleMount( system->mntPoint() );
 
352
         break;
 
353
         case FORMAT_ID :
 
354
         break;
 
355
         case EJECT_ID :
 
356
         KMountMan::eject( system->mntPoint() );
 
357
         break;
 
358
   }
243
359
}
244
360
 
245
361
#include "kmountmangui.moc"