2010-02-17 13:18:25 +00:00
/***************************************************************************
* Copyright ( C ) 2010 by Volker Lanz < vl @ fidra . de > *
* *
* 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 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-03-21 11:32:31 +00:00
# include "config/configureoptionsdialog.h"
2010-03-21 11:52:07 +00:00
# include "config/generalpagewidget.h"
# include "config/filesystemcolorspagewidget.h"
2010-06-02 15:35:02 +01:00
# include "config/advancedpagewidget.h"
2010-02-17 13:18:25 +00:00
2010-03-21 10:50:44 +00:00
# include "backend/corebackendmanager.h"
2010-03-24 23:30:20 +00:00
# include "core/operationstack.h"
2010-03-11 14:17:21 +00:00
# include "fs/filesystem.h"
# include "fs/filesystemfactory.h"
# include "util/helpers.h"
2010-02-17 19:39:24 +00:00
# include "ui_configurepagefilesystemcolors.h"
2010-02-17 13:18:25 +00:00
2014-11-19 12:05:22 +00:00
# include <KIconLoader>
2014-05-13 23:53:37 +01:00
# include <KLocalizedString>
2014-05-18 21:41:48 +01:00
# include <KMessageBox>
2010-03-11 19:40:42 +00:00
2014-05-17 02:27:42 +01:00
# include <QIcon>
2010-03-11 14:17:21 +00:00
# include <config.h>
2010-03-03 10:46:23 +00:00
2010-03-24 23:30:20 +00:00
ConfigureOptionsDialog : : ConfigureOptionsDialog ( QWidget * parent , const OperationStack & ostack , const QString & name ) :
2010-03-11 19:40:42 +00:00
KConfigDialog ( parent , name , Config : : self ( ) ) ,
2010-03-11 14:17:21 +00:00
m_GeneralPageWidget ( new GeneralPageWidget ( this ) ) ,
2010-03-24 23:30:20 +00:00
m_FileSystemColorsPageWidget ( new FileSystemColorsPageWidget ( this ) ) ,
2010-06-02 15:35:02 +01:00
m_AdvancedPageWidget ( new AdvancedPageWidget ( this ) ) ,
2010-03-24 23:30:20 +00:00
m_OperationStack ( ostack )
2010-02-17 13:18:25 +00:00
{
2010-03-03 10:46:23 +00:00
setFaceType ( List ) ;
KPageWidgetItem * item = NULL ;
2010-03-11 16:34:48 +00:00
item = addPage ( & generalPageWidget ( ) , i18nc ( " @title:tab general application settings " , " General " ) , QString ( ) , i18n ( " General Settings " ) ) ;
2014-05-18 21:41:48 +01:00
item - > setIcon ( KIconLoader ( ) . loadIcon ( QLatin1String ( " partitionmanager " ) , KIconLoader : : Desktop ) ) ;
2010-03-03 10:46:23 +00:00
2010-03-11 19:40:42 +00:00
connect ( & generalPageWidget ( ) . comboDefaultFileSystem ( ) , SIGNAL ( activated ( int ) ) , SLOT ( onComboDefaultFileSystemActivated ( int ) ) ) ;
2014-05-29 02:45:36 +01:00
connect ( generalPageWidget ( ) . radioButton , & QRadioButton : : toggled , this , & ConfigureOptionsDialog : : onShredSourceActivated ) ;
2010-03-21 10:50:44 +00:00
2010-03-11 16:34:48 +00:00
item = addPage ( & fileSystemColorsPageWidget ( ) , i18nc ( " @title:tab " , " File System Colors " ) , QString ( ) , i18n ( " File System Color Settings " ) ) ;
2014-05-18 21:41:48 +01:00
item - > setIcon ( KIconLoader ( ) . loadIcon ( QLatin1String ( " format-fill-color " ) , KIconLoader : : Desktop ) ) ;
2010-03-03 10:46:23 +00:00
2014-05-18 21:41:48 +01:00
if ( QCoreApplication : : arguments ( ) . contains ( QLatin1String ( " --advconfig " ) ) )
2010-06-02 21:39:25 +01:00
{
item = addPage ( & advancedPageWidget ( ) , i18nc ( " @title:tab advanced application settings " , " Advanced " ) , QString ( ) , i18n ( " Advanced Settings " ) ) ;
2014-05-18 21:41:48 +01:00
item - > setIcon ( KIconLoader ( ) . loadIcon ( QLatin1String ( " configure " ) , KIconLoader : : Desktop ) ) ;
2010-06-02 15:35:02 +01:00
2010-06-02 21:39:25 +01:00
connect ( & advancedPageWidget ( ) . comboBackend ( ) , SIGNAL ( activated ( int ) ) , SLOT ( onComboBackendActivated ( int ) ) ) ;
}
else
advancedPageWidget ( ) . setVisible ( false ) ;
2010-06-02 15:35:02 +01:00
2014-05-18 21:41:48 +01:00
KConfigGroup kcg ( KSharedConfig : : openConfig ( ) , " configureOptionsDialogs " ) ;
restoreGeometry ( kcg . readEntry < QByteArray > ( " Geometry " , QByteArray ( ) ) ) ;
2010-02-21 17:03:22 +00:00
}
/** Destroys a ConfigureOptionsDialog instance */
ConfigureOptionsDialog : : ~ ConfigureOptionsDialog ( )
{
2014-05-18 21:41:48 +01:00
KConfigGroup kcg ( KSharedConfig : : openConfig ( ) , " configureOptionsDialog " ) ;
kcg . writeEntry ( " Geometry " , saveGeometry ( ) ) ;
2010-02-17 13:18:25 +00:00
}
2010-03-11 19:40:42 +00:00
void ConfigureOptionsDialog : : updateSettings ( )
{
2010-03-21 10:50:44 +00:00
KConfigDialog : : updateSettings ( ) ;
bool changed = false ;
if ( generalPageWidget ( ) . defaultFileSystem ( ) ! = Config : : defaultFileSystem ( ) )
{
Config : : setDefaultFileSystem ( generalPageWidget ( ) . defaultFileSystem ( ) ) ;
changed = true ;
}
2014-05-29 02:45:36 +01:00
if ( generalPageWidget ( ) . radioButton - > isChecked ( ) ! = ( Config : : shredSource ( ) = = Config : : EnumShredSource : : random ) )
{
qDebug ( ) < < " updateSettings: " < < generalPageWidget ( ) . kcfg_shredSource - > checkedId ( ) ;
Config : : setShredSource ( generalPageWidget ( ) . kcfg_shredSource - > checkedId ( ) ) ;
changed = true ;
}
2010-06-02 21:39:25 +01:00
if ( advancedPageWidget ( ) . isVisible ( ) & & advancedPageWidget ( ) . backend ( ) ! = Config : : backend ( ) )
2010-03-21 10:50:44 +00:00
{
2010-06-02 15:35:02 +01:00
Config : : setBackend ( advancedPageWidget ( ) . backend ( ) ) ;
2010-03-21 10:50:44 +00:00
changed = true ;
}
if ( changed )
emit KConfigDialog : : settingsChanged ( i18n ( " General Settings " ) ) ;
}
bool ConfigureOptionsDialog : : hasChanged ( )
{
bool result = KConfigDialog : : hasChanged ( ) ;
2014-05-20 22:33:02 +01:00
KConfigSkeletonItem * kcItem = Config : : self ( ) - > findItem ( QStringLiteral ( " defaultFileSystem " ) ) ;
2010-03-21 10:50:44 +00:00
result = result | | ! kcItem - > isEqual ( generalPageWidget ( ) . defaultFileSystem ( ) ) ;
2014-05-29 02:45:36 +01:00
result = result | | ( generalPageWidget ( ) . kcfg_shredSource - > checkedId ( ) ! = Config : : shredSource ( ) ) ;
2010-03-21 10:50:44 +00:00
2010-06-02 21:39:25 +01:00
if ( advancedPageWidget ( ) . isVisible ( ) )
{
2014-05-20 22:33:02 +01:00
kcItem = Config : : self ( ) - > findItem ( QStringLiteral ( " backend " ) ) ;
2010-06-02 21:39:25 +01:00
result = result | | ! kcItem - > isEqual ( advancedPageWidget ( ) . backend ( ) ) ;
}
2010-03-21 10:50:44 +00:00
return result ;
2010-03-11 19:40:42 +00:00
}
bool ConfigureOptionsDialog : : isDefault ( )
{
2010-03-21 10:50:44 +00:00
bool result = KConfigDialog : : isDefault ( ) ;
2010-03-11 19:40:42 +00:00
if ( result )
{
const bool useDefaults = Config : : self ( ) - > useDefaults ( true ) ;
2010-03-21 10:50:44 +00:00
result = ! hasChanged ( ) ;
2010-03-11 19:40:42 +00:00
Config : : self ( ) - > useDefaults ( useDefaults ) ;
}
return result ;
}
void ConfigureOptionsDialog : : updateWidgetsDefault ( )
{
bool useDefaults = Config : : self ( ) - > useDefaults ( true ) ;
generalPageWidget ( ) . setDefaultFileSystem ( FileSystem : : defaultFileSystem ( ) ) ;
2014-05-29 02:45:36 +01:00
generalPageWidget ( ) . radioButton - > setChecked ( true ) ;
2010-06-02 21:39:25 +01:00
if ( advancedPageWidget ( ) . isVisible ( ) )
advancedPageWidget ( ) . setBackend ( CoreBackendManager : : defaultBackendName ( ) ) ;
2010-03-11 19:40:42 +00:00
Config : : self ( ) - > useDefaults ( useDefaults ) ;
}
2010-03-24 23:30:20 +00:00
void ConfigureOptionsDialog : : onComboBackendActivated ( int )
{
2010-06-02 21:39:25 +01:00
Q_ASSERT ( advancedPageWidget ( ) . isVisible ( ) ) ;
2010-03-24 23:30:20 +00:00
if ( operationStack ( ) . size ( ) = = 0 | | KMessageBox : : warningContinueCancel ( this ,
2014-05-18 21:41:48 +01:00
xi18nc ( " @info " ,
2010-03-24 23:30:20 +00:00
" <para>Do you really want to change the backend?</para> "
" <para><warning>This will also rescan devices and thus clear the list of pending operations.</warning></para> " ) ,
i18nc ( " @title:window " , " Really Change Backend? " ) ,
2014-05-20 22:33:02 +01:00
KGuiItem ( i18nc ( " @action:button " , " Change the Backend " ) , QStringLiteral ( " arrow-right " ) ) ,
KGuiItem ( i18nc ( " @action:button " , " Do Not Change the Backend " ) , QStringLiteral ( " dialog-cancel " ) ) , QStringLiteral ( " reallyChangeBackend " ) ) = = KMessageBox : : Continue )
2010-03-24 23:30:20 +00:00
{
settingsChangedSlot ( ) ;
}
else
2010-06-02 15:35:02 +01:00
advancedPageWidget ( ) . setBackend ( CoreBackendManager : : defaultBackendName ( ) ) ;
2010-03-24 23:30:20 +00:00
}