• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kdf

mntconfig.cpp

Go to the documentation of this file.
00001 /*
00002  * mntconfig.cpp
00003  *
00004  * Copyright (c) 1999 Michael Kropfberger <michael.kropfberger@gmx.net>
00005  *
00006  * Requires the Qt widget libraries, available at no cost at
00007  * http://www.troll.no/
00008  *
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00022  */
00023 
00024 //
00025 // 1999-11-29 Espen Sand
00026 // Converted to QLayout and QListView + cleanups
00027 //
00028 
00029 #include "mntconfig.h"
00030 
00031 #include <Qt3Support/Q3GroupBox>
00032 #include <Qt3Support/Q3Header>
00033 #include <QtGui/QLayout>
00034 #include <KLineEdit>
00035 //Added by qt3to4:
00036 #include <QtGui/QPixmap>
00037 #include <QtGui/QVBoxLayout>
00038 #include <QtGui/QFrame>
00039 #include <QtGui/QGridLayout>
00040 #include <QtGui/QCloseEvent>
00041 
00042 #undef Unsorted
00043 
00044 #include <kfiledialog.h>
00045 #include <kicondialog.h>
00046 #include <kmessagebox.h>
00047 #include <kglobal.h>
00048 
00049 #include "listview.h"
00050 
00051 #ifndef KDE_USE_FINAL
00052 static bool GUI;
00053 #endif
00054 
00055 MntConfigWidget::MntConfigWidget(QWidget *parent, bool init)
00056   : QWidget(parent)
00057 {
00058   mInitializing = false;
00059 
00060   GUI = !init;
00061   if (GUI)
00062   {
00063     //tabList fillup waits until disklist.readDF() is done...
00064     mDiskList.readFSTAB();
00065     mDiskList.readDF();
00066     mInitializing = true;
00067     connect( &mDiskList,SIGNAL(readDFDone()),this,SLOT(readDFDone()));
00068 
00069     QString text;
00070     QVBoxLayout *topLayout = new QVBoxLayout( this );
00071     topLayout->setSpacing( KDialog::spacingHint() );
00072     topLayout->setMargin( 0 );
00073 
00074     mList = new CListView( this, "list", 8 );
00075     mList->setAllColumnsShowFocus( true );
00076     mList->addColumn( i18n("Icon") );
00077     mList->addColumn( i18n("Device") );
00078     mList->addColumn( i18n("Mount Point") );
00079     mList->addColumn( i18n("Mount Command") );
00080     mList->addColumn( i18n("Unmount Command") );
00081     mList->setFrameStyle( QFrame::WinPanel + QFrame::Sunken );
00082     connect( mList, SIGNAL(selectionChanged(Q3ListViewItem *)),
00083          this, SLOT(clicked(Q3ListViewItem *)));
00084 
00085     topLayout->addWidget( mList );
00086 
00087     text = QString("%1: %2  %3: %4").
00088       arg(mList->header()->label(DEVCOL)).
00089       arg(i18nc("No device is selected", "None")).
00090       arg(mList->header()->label(MNTPNTCOL)).
00091       arg(i18nc("No mount point is selected", "None"));
00092     mGroupBox = new QGroupBox( text, this );
00093     Q_CHECK_PTR(mGroupBox);
00094     mGroupBox->setEnabled( false );
00095     topLayout->addWidget(mGroupBox);
00096 
00097     QGridLayout *gl = new QGridLayout( mGroupBox );
00098     gl->setSpacing( KDialog::spacingHint() );
00099     gl->addItem( new QSpacerItem( 0, fontMetrics().lineSpacing() ), 0, 0 );
00100 
00101     mIconLineEdit = new KLineEdit(mGroupBox);
00102     Q_CHECK_PTR(mIconLineEdit);
00103     mIconLineEdit->setMinimumWidth( fontMetrics().maxWidth()*10 );
00104     connect( mIconLineEdit, SIGNAL(textChanged(const QString&)),
00105          this,SLOT(iconChanged(const QString&)));
00106     connect( mIconLineEdit, SIGNAL(textChanged(const QString&)),
00107          this,SLOT(slotChanged()));
00108     gl->addWidget( mIconLineEdit, 2, 0 );
00109 
00110     mIconButton = new KIconButton(mGroupBox);
00111     mIconButton->setIconType(KIconLoader::Small, KIconLoader::Device);
00112     Q_CHECK_PTR(mIconButton);
00113     mIconButton->setFixedWidth( mIconButton->sizeHint().height() );
00114     connect(mIconButton,SIGNAL(iconChanged(QString)),this,SLOT(iconChangedButton(QString)));
00115     gl->addWidget( mIconButton, 2, 1 );
00116 
00117     //Mount
00118     mMountButton = new QPushButton( i18n("Get Mount Command"), mGroupBox );
00119     Q_CHECK_PTR(mMountButton);
00120     connect(mMountButton,SIGNAL(clicked()),this,SLOT(selectMntFile()));
00121     gl->addWidget( mMountButton, 1, 2 );
00122 
00123     mMountLineEdit = new KLineEdit(mGroupBox);
00124     Q_CHECK_PTR(mMountLineEdit);
00125     mMountLineEdit->setMinimumWidth( fontMetrics().maxWidth()*10 );
00126     connect(mMountLineEdit,SIGNAL(textChanged(const QString&)),
00127         this,SLOT(mntCmdChanged(const QString&)));
00128     connect( mMountLineEdit, SIGNAL(textChanged(const QString&)),
00129          this,SLOT(slotChanged()));
00130     gl->addWidget( mMountLineEdit, 1, 3 );
00131 
00132     //Umount
00133     mUmountButton = new QPushButton(i18n("Get Unmount Command"), mGroupBox );
00134     Q_CHECK_PTR( mUmountButton );
00135     connect(mUmountButton,SIGNAL(clicked()),this,SLOT(selectUmntFile()));
00136     gl->addWidget( mUmountButton, 2, 2 );
00137 
00138     mUmountLineEdit=new KLineEdit(mGroupBox);
00139     Q_CHECK_PTR(mUmountLineEdit);
00140     mUmountLineEdit->setMinimumWidth( fontMetrics().maxWidth()*10 );
00141     connect(mUmountLineEdit,SIGNAL(textChanged(const QString&)),
00142         this,SLOT(umntCmdChanged(const QString&)));
00143     connect( mUmountLineEdit, SIGNAL(textChanged(const QString&)),
00144          this,SLOT(slotChanged()));
00145     gl->addWidget( mUmountLineEdit, 2, 3 );
00146 
00147   }
00148 
00149   loadSettings();
00150   if(init)
00151   {
00152     applySettings();
00153     mDiskLookup.resize(0);
00154   }
00155 }
00156 
00157 
00158 MntConfigWidget::~MntConfigWidget( void )
00159 {
00160 }
00161 
00162 
00163 void MntConfigWidget::readDFDone( void )
00164 {
00165   mInitializing = false;
00166   mList->clear();
00167   mDiskLookup.resize(mDiskList.count());
00168 
00169   int i=0;
00170   Q3ListViewItem *item = 0;
00171   for( DiskEntry *disk=mDiskList.first(); disk!=0; disk=mDiskList.next(),++i )
00172   {
00173      item = new Q3ListViewItem( mList, item, QString(), disk->deviceName(),
00174       disk->mountPoint(), disk->mountCommand(), disk->umountCommand() );
00175      item->setPixmap( ICONCOL, SmallIcon( disk->iconName() ) );
00176      mDiskLookup[i] = item;
00177   }
00178 
00179   loadSettings();
00180   applySettings();
00181 }
00182 
00183 
00184 void MntConfigWidget::applySettings( void )
00185 {
00186   mDiskList.applySettings();
00187 
00188   KConfigGroup config(KGlobal::config(), "MntConfig");
00189   if(GUI )
00190   {
00191    config.writeEntry("Width", width() );
00192    config.writeEntry("Height", height() );
00193   }
00194   config.sync();
00195 }
00196 
00197 
00198 void MntConfigWidget::loadSettings( void )
00199 {
00200   KConfigGroup config = KGlobal::config()->group("MntConfig");
00201   if( mInitializing == false && GUI )
00202   {
00203     if( isTopLevel() )
00204     {
00205       int w = config.readEntry("Width",this->width() );
00206       int h = config.readEntry("Height",this->height() );
00207       resize(w,h);
00208     }
00209 
00210     Q3ListViewItem *item = mList->selectedItem();
00211     if( item != 0 )
00212     {
00213       clicked( item );
00214     }
00215   }
00216 }
00217 
00218 
00219 void MntConfigWidget::clicked( Q3ListViewItem *item )
00220 {
00221   mGroupBox->setEnabled( true );
00222   mGroupBox->setTitle( QString("%1: %2  %3: %4").
00223     arg(mList->header()->label(DEVCOL)).
00224     arg(item->text(DEVCOL)).
00225     arg(mList->header()->label(MNTPNTCOL)).
00226     arg(item->text(MNTPNTCOL)) );
00227 
00228 
00229   const QPixmap *pix = item->pixmap(ICONCOL);
00230   if( pix != 0 )
00231   {
00232     mIconButton->setIcon( *pix );
00233   }
00234 
00235   for(unsigned i=0 ; i < mDiskList.count() ; ++i)
00236     {
00237       if (mDiskLookup[i] == item)
00238     {
00239       DiskEntry *disk = mDiskList.at(i);
00240       if( disk != 0 )
00241         {
00242           mIconLineEdit->setText( disk->iconName() );
00243         }
00244       break;
00245     }
00246     }
00247   mMountLineEdit->setText( item->text(MNTCMDCOL) );
00248   mUmountLineEdit->setText( item->text(UMNTCMDCOL) );
00249 }
00250 
00251 
00252 void MntConfigWidget::iconChangedButton(const QString &iconName)
00253 {
00254   iconChanged(iconName);
00255 }
00256 
00257 void MntConfigWidget::iconChanged(const QString &iconName)
00258 {
00259     int pos = iconName.lastIndexOf('_');
00260   if( pos == 0 ||
00261       (iconName.mid(pos)!="_mount" &&
00262        iconName.mid(pos)!="_unmount"))
00263     {
00264       QString msg = i18n(""
00265              "This filename is not valid: %1\n"
00266              "It must end with "
00267              "\"_mount\" or \"_unmount\".", iconName);
00268       KMessageBox::sorry( this, msg );
00269       return;
00270     }
00271 
00272   Q3ListViewItem *item = mList->selectedItem();
00273   for(unsigned i=0 ; i < mDiskList.count() ; ++i)
00274     {
00275       if (mDiskLookup[i] == item)
00276     {
00277       DiskEntry *disk = mDiskList.at(i);
00278       if( disk != 0 )
00279         {
00280           disk->setIconName(iconName);
00281           mIconLineEdit->setText(iconName);
00282           KIconLoader &loader = *KIconLoader::global();
00283           item->setPixmap( ICONCOL, loader.loadIcon( iconName, KIconLoader::Small));
00284         }
00285       break;
00286     }
00287     }
00288 }
00289 
00290 
00291 void MntConfigWidget::selectMntFile()
00292 {
00293   KUrl url = KFileDialog::getOpenUrl( KUrl(),"*", this );
00294 
00295   if( url.isEmpty() )
00296     return;
00297 
00298   if( !url.isLocalFile() )
00299   {
00300     KMessageBox::sorry( 0L, i18n( "Only local files supported." ) );
00301     return;
00302   }
00303 
00304   mMountLineEdit->setText( url.path() );
00305 }
00306 
00307 void MntConfigWidget::selectUmntFile()
00308 {
00309   KUrl url = KFileDialog::getOpenUrl( KUrl(), "*", this );
00310 
00311   if( url.isEmpty() )
00312     return;
00313 
00314   if( !url.isLocalFile() )
00315   {
00316     KMessageBox::sorry( 0L, i18n( "Only local files are currently supported." ) );
00317     return;
00318   }
00319 
00320   mUmountLineEdit->setText( url.path() );
00321 }
00322 
00323 void MntConfigWidget::mntCmdChanged( const QString &data )
00324 {
00325   Q3ListViewItem *item = mList->selectedItem();
00326   for(unsigned  i=0 ; i < mDiskList.count() ; ++i)
00327     {
00328       if (mDiskLookup[i] == item)
00329     {
00330       DiskEntry *disk = mDiskList.at(i);
00331       if( disk != 0 )
00332         {
00333           disk->setMountCommand(data);
00334           item->setText( MNTCMDCOL, data );
00335         }
00336       break;
00337     }
00338     }
00339 }
00340 
00341 
00342 void MntConfigWidget::umntCmdChanged( const QString &data )
00343 {
00344   Q3ListViewItem *item = mList->selectedItem();
00345   for(unsigned i=0 ; i < mDiskList.count() ; ++i)
00346     {
00347     if (mDiskLookup[i] == item)
00348       {
00349     DiskEntry *disk = mDiskList.at(i);
00350     if( disk != 0 )
00351       {
00352         disk->setUmountCommand(data);
00353         item->setText( UMNTCMDCOL, data );
00354       }
00355     break;
00356       }
00357     }
00358 }
00359 
00360 
00361 void MntConfigWidget::closeEvent(QCloseEvent *)
00362 {
00363 }
00364 
00365 void MntConfigWidget::slotChanged()
00366 {
00367   emit configChanged();
00368 }
00369 
00370 #include "mntconfig.moc"

kdf

Skip menu "kdf"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal