00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "kdfconfig.h"
00030
00031 #include <QtGui/QCheckBox>
00032 #include <Qt3Support/Q3Header>
00033 #include <QtGui/QLabel>
00034 #include <QtGui/QLayout>
00035 #include <QtGui/QLCDNumber>
00036 #include <KLineEdit>
00037
00038 #include <QtGui/QVBoxLayout>
00039 #include <QtGui/QFrame>
00040 #include <QtGui/QGridLayout>
00041 #include <QtGui/QCloseEvent>
00042
00043 #include <kapplication.h>
00044 #include <kconfig.h>
00045 #include <kdialog.h>
00046 #include <klocale.h>
00047 #include <kiconloader.h>
00048 #include <kglobal.h>
00049
00050 #include "listview.h"
00051
00052 #ifndef GUI_DEFINED
00053 static bool GUI;
00054 #define GUI_DEFINED
00055 #endif
00056
00057
00058 KDFConfigWidget::KDFConfigWidget(QWidget *parent, bool init)
00059 : QWidget( parent)
00060 {
00061
00062 mTabName.resize(8);
00063 mTabName[0] = new CTabName( "Icon", i18nc("Storage device icon", "Icon") );
00064 mTabName[1] = new CTabName( "Device", i18nc("Device of the storage", "Device") );
00065 mTabName[2] = new CTabName( "Type", i18nc("Filesystem on storage", "Type") );
00066 mTabName[3] = new CTabName( "Size", i18nc("Total size of the storage", "Size") );
00067 mTabName[4] = new CTabName( "MountPoint", i18nc("Mount point of the storage", "Mount Point") );
00068 mTabName[5] = new CTabName( "Free", i18nc("Free space in storage", "Free") );
00069
00070 mTabName[6] = new CTabName( "Full%", i18nc("Used storage space in %", "Full %") );
00071 mTabName[7] = new CTabName( "UsageBar", i18nc("Usage graphical bar", "Usage") );
00072
00073 GUI = !init;
00074 if(GUI)
00075 {
00076 QString text;
00077 QVBoxLayout *topLayout = new QVBoxLayout( this );
00078 topLayout->setSpacing( KDialog::spacingHint() );
00079 topLayout->setMargin( 0 );
00080
00081 mList = new CListView( this, "list", 1 );
00082 mList->setAllColumnsShowFocus(true);
00083 mList->setFrameStyle( QFrame::WinPanel + QFrame::Sunken );
00084 mList->header()->setMovingEnabled(false);
00085 for( int i=0; i < mTabName.size(); i++ )
00086 {
00087 mList->addColumn( mTabName[i]->mName );
00088 }
00089 connect( mList, SIGNAL(clicked(Q3ListViewItem *, const QPoint &, int)),
00090 this, SLOT(toggleListText(Q3ListViewItem *,const QPoint &,int)));
00091 connect( mList, SIGNAL(clicked(Q3ListViewItem *, const QPoint &, int)),
00092 this, SLOT(slotChanged()));
00093 topLayout->addWidget( mList );
00094
00095 Q3ListViewItem *mListItem = new Q3ListViewItem( mList );
00096 for( uint i=mList->header()->count(); i>0; i-- )
00097 {
00098 mListItem->setText( i-1, i18nc("Visible items on device information columns (enable|disable)", "visible") );
00099 mListItem->setPixmap( i-1, UserIcon ( "tick" ) );
00100 }
00101 mList->setSelected( mListItem, true );
00102
00103 QGridLayout *gl = new QGridLayout( );
00104 topLayout->addLayout( gl );
00105 gl->setColumnStretch( 1, 10 );
00106
00107 mScroll = new QScrollBar( this );
00108 Q_CHECK_PTR(mScroll);
00109 mScroll->setOrientation( Qt::Horizontal );
00110 mScroll->setSingleStep(1);
00111 mScroll->setPageStep(20);
00112 mScroll->setRange(0, 180 );
00113 gl->addWidget( mScroll, 1, 1 );
00114 connect(mScroll,SIGNAL(valueChanged(int)),this,SLOT(slotChanged()));
00115
00116 mLCD = new QLCDNumber( this );
00117 Q_CHECK_PTR(mLCD);
00118 mLCD->setNumDigits( 3 );
00119 mLCD->setSegmentStyle(QLCDNumber::Filled);
00120 connect(mScroll,SIGNAL(valueChanged(int)),mLCD,SLOT(display(int)));
00121 gl->addWidget( mLCD, 0, 0, 1, 1 );
00122
00123 text = i18n("Update frequency [seconds]. The value 0 disables update" );
00124 QLabel *label = new QLabel( text, this );
00125 Q_CHECK_PTR(label);
00126 gl->addWidget( label, 0, 1 );
00127
00128
00129 label = new QLabel( i18n("File manager (e.g. konsole -e mc %m):") ,this);
00130 Q_CHECK_PTR(label);
00131 topLayout->addWidget( label );
00132
00133 mFileManagerEdit = new KLineEdit( this );
00134 Q_CHECK_PTR(mFileManagerEdit);
00135 topLayout->addWidget( mFileManagerEdit );
00136 connect(mFileManagerEdit,SIGNAL(textChanged (const QString &)),this,SLOT(slotChanged()));
00137
00138 text = i18n("Open file manager automatically on mount");
00139 mOpenMountCheck = new QCheckBox(text, this );
00140 Q_CHECK_PTR(mOpenMountCheck);
00141 topLayout->addWidget( mOpenMountCheck );
00142 connect(mOpenMountCheck,SIGNAL(toggled(bool)),this,SLOT(slotChanged()));
00143
00144 text = i18n("Pop up a window when a disk gets critically full");
00145 mPopupFullCheck = new QCheckBox( text, this );
00146 Q_CHECK_PTR(mPopupFullCheck);
00147 topLayout->addWidget( mPopupFullCheck );
00148 connect(mPopupFullCheck,SIGNAL(toggled(bool)),this,SLOT(slotChanged()));
00149 }
00150
00151 loadSettings();
00152 if( init )
00153 {
00154 applySettings();
00155 }
00156 }
00157
00158
00159 KDFConfigWidget::~KDFConfigWidget()
00160 {
00161 }
00162
00163
00164 void KDFConfigWidget::closeEvent(QCloseEvent *)
00165 {
00166 applySettings();
00167 kapp->quit();
00168 }
00169
00170
00171 void KDFConfigWidget::applySettings( void )
00172 {
00173 KConfigGroup config(KGlobal::config(), "KDFConfig");
00174
00175 if( GUI )
00176 {
00177
00178
00179
00180 mStd.setFileManager( mFileManagerEdit->text() );
00181 mStd.setUpdateFrequency( mScroll->value() );
00182 mStd.setPopupIfFull( mPopupFullCheck->isChecked() );
00183 mStd.setOpenFileManager( mOpenMountCheck->isChecked() );
00184 mStd.writeConfiguration();
00185
00186 Q3ListViewItem *item = mList->firstChild();
00187 if( item != 0 )
00188 {
00189 for( int i=mList->header()->count(); i>0; i-- )
00190 {
00191 bool state = item->text(i-1) == i18nc("Visible items on device information columns (enable|disable)", "visible") ? true : false;
00192 config.writeEntry( mTabName[i-1]->mRes, state );
00193 }
00194 }
00195 }
00196 else
00197 {
00198 mStd.writeDefaultFileManager();
00199 }
00200 config.sync();
00201 }
00202
00203
00204 void KDFConfigWidget::loadSettings( void )
00205 {
00206 KConfigGroup config(KGlobal::config(), "KDFConfig");
00207
00208 if( GUI )
00209 {
00210 mStd.updateConfiguration();
00211 mScroll->setValue( mStd.updateFrequency() );
00212 mLCD->display( mStd.updateFrequency() );
00213 mPopupFullCheck->setChecked( mStd.popupIfFull() );
00214 mOpenMountCheck->setChecked( mStd.openFileManager() );
00215 mFileManagerEdit->setText( mStd.fileManager() );
00216
00217 Q3ListViewItem *item = mList->firstChild();
00218 if( item != 0 )
00219 {
00220 for( int i=mList->header()->count(); i>0; i-- )
00221 {
00222 int j = config.readEntry( mTabName[i-1]->mRes, 1 );
00223 item->setText( i-1, j==0 ? i18nc("Are items on device information columns hidden?", "hidden") : i18nc("Are items on device information columns visible?", "visible") );
00224 item->setPixmap( i-1, j==0 ? UserIcon ( "delete" )
00225 : UserIcon ( "tick" ) );
00226 }
00227 }
00228 }
00229
00230 }
00231
00232 void KDFConfigWidget::defaultsBtnClicked( void )
00233 {
00234 mStd.setDefault();
00235 mScroll->setValue( mStd.updateFrequency() );
00236 mLCD->display( mStd.updateFrequency() );
00237 mPopupFullCheck->setChecked( mStd.popupIfFull() );
00238 mOpenMountCheck->setChecked( mStd.openFileManager() );
00239 mFileManagerEdit->setText( mStd.fileManager() );
00240
00241 Q3ListViewItem *item = mList->firstChild();
00242 if( item != 0 )
00243 {
00244 for( int i=mList->header()->count(); i>0; i-- )
00245 {
00246 item->setText( i-1, i18nc("Item on the device information column is visible", "visible") );
00247 item->setPixmap( i-1, UserIcon ( "tick" ) );
00248
00249 }
00250 }
00251 }
00252
00253
00254 void KDFConfigWidget::toggleListText( Q3ListViewItem *item, const QPoint &,
00255 int column )
00256 {
00257 if (!item) return;
00258 QString text = item->text( column );
00259 item->setText(column, text==i18nc("Device information item is visible", "visible")?i18nc("Device information item is hidden", "hidden"):i18nc("Device information item is visible", "visible"));
00260 item->setPixmap( column, text==i18nc("Device information item is visible", "visible") ? UserIcon ( "delete" )
00261 : UserIcon ( "tick" ) );
00262 }
00263
00264 void KDFConfigWidget::slotChanged()
00265 {
00266 emit configChanged();
00267 }
00268
00269 #include "kdfconfig.moc"