2015-02-07 00:32:25 +00:00
/*************************************************************************
* Copyright ( C ) 2010 by Volker Lanz < vl @ fidra . de > *
2016-03-02 18:33:40 +00:00
* Copyright ( C ) 2016 by Andrius Š tikonas < andrius @ stikonas . eu > *
2015-02-07 00:32:25 +00:00
* *
* 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 3 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 , see < http : //www.gnu.org/licenses/>.*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-02-17 13:18:25 +00:00
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
2016-01-12 00:12:49 +00:00
# include <backend/corebackendmanager.h>
2010-03-21 10:50:44 +00:00
2016-01-12 00:12:49 +00:00
# include <core/operationstack.h>
2010-03-24 23:30:20 +00:00
2016-01-12 00:12:49 +00:00
# include <fs/filesystem.h>
# include <fs/filesystemfactory.h>
2010-03-11 14:17:21 +00:00
2016-01-12 00:12:49 +00:00
# include <util/helpers.h>
2015-06-30 20:22:13 +01:00
# include "util/guihelpers.h"
2010-03-11 14:17:21 +00:00
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 ) :
2015-07-13 15:17:41 +01:00
KConfigDialog ( parent , name , Config : : self ( ) ) ,
m_GeneralPageWidget ( new GeneralPageWidget ( this ) ) ,
m_FileSystemColorsPageWidget ( new FileSystemColorsPageWidget ( this ) ) ,
m_AdvancedPageWidget ( new AdvancedPageWidget ( this ) ) ,
m_OperationStack ( ostack )
2010-02-17 13:18:25 +00:00
{
2015-07-13 15:17:41 +01:00
setFaceType ( List ) ;
2010-03-03 10:46:23 +00:00
2016-04-14 19:18:36 +01:00
KPageWidgetItem * item = nullptr ;
2010-03-03 10:46:23 +00:00
2015-07-13 15:17:41 +01:00
item = addPage ( & generalPageWidget ( ) , i18nc ( " @title:tab general application settings " , " General " ) , QString ( ) , i18n ( " General Settings " ) ) ;
item - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " partitionmanager " ) ) . pixmap ( IconSize ( KIconLoader : : Desktop ) ) ) ;
2010-03-03 10:46:23 +00:00
2016-05-22 20:03:49 +01:00
connect ( & generalPageWidget ( ) . comboDefaultFileSystem ( ) , static_cast < void ( QComboBox : : * ) ( int ) > ( & QComboBox : : activated ) , this , & ConfigureOptionsDialog : : onComboDefaultFileSystemActivated ) ;
2015-07-13 15:17:41 +01:00
connect ( generalPageWidget ( ) . radioButton , & QRadioButton : : toggled , this , & ConfigureOptionsDialog : : onShredSourceActivated ) ;
2010-03-21 10:50:44 +00:00
2015-07-13 15:17:41 +01:00
item = addPage ( & fileSystemColorsPageWidget ( ) , i18nc ( " @title:tab " , " File System Colors " ) , QString ( ) , i18n ( " File System Color Settings " ) ) ;
item - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " format-fill-color " ) ) . pixmap ( IconSize ( KIconLoader : : Desktop ) ) ) ;
2010-03-03 10:46:23 +00:00
2015-07-13 15:17:41 +01:00
if ( QCoreApplication : : arguments ( ) . contains ( QLatin1String ( " --advconfig " ) ) ) {
item = addPage ( & advancedPageWidget ( ) , i18nc ( " @title:tab advanced application settings " , " Advanced " ) , QString ( ) , i18n ( " Advanced Settings " ) ) ;
item - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " configure " ) ) . pixmap ( IconSize ( KIconLoader : : Desktop ) ) ) ;
2010-06-02 15:35:02 +01:00
2016-05-22 20:03:49 +01:00
connect ( & advancedPageWidget ( ) . comboBackend ( ) , static_cast < void ( QComboBox : : * ) ( int ) > ( & QComboBox : : activated ) , this , & ConfigureOptionsDialog : : onComboDefaultFileSystemActivated ) ;
2015-07-13 15:17:41 +01:00
} else
advancedPageWidget ( ) . setVisible ( false ) ;
2010-06-02 15:35:02 +01:00
2015-07-13 15:17:41 +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 ( )
{
2015-07-13 15:17:41 +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 ( )
{
2015-07-13 15:17:41 +01:00
KConfigDialog : : updateSettings ( ) ;
bool changed = false ;
if ( generalPageWidget ( ) . defaultFileSystem ( ) ! = Config : : defaultFileSystem ( ) ) {
Config : : setDefaultFileSystem ( generalPageWidget ( ) . defaultFileSystem ( ) ) ;
changed = true ;
}
if ( generalPageWidget ( ) . radioButton - > isChecked ( ) ! = ( Config : : shredSource ( ) = = Config : : EnumShredSource : : random ) ) {
qDebug ( ) < < " updateSettings: " < < generalPageWidget ( ) . kcfg_shredSource - > checkedId ( ) ;
Config : : setShredSource ( generalPageWidget ( ) . kcfg_shredSource - > checkedId ( ) ) ;
changed = true ;
}
if ( advancedPageWidget ( ) . isVisible ( ) & & advancedPageWidget ( ) . backend ( ) ! = Config : : backend ( ) ) {
Config : : setBackend ( advancedPageWidget ( ) . backend ( ) ) ;
changed = true ;
}
if ( changed )
emit KConfigDialog : : settingsChanged ( i18n ( " General Settings " ) ) ;
2010-03-21 10:50:44 +00:00
}
bool ConfigureOptionsDialog : : hasChanged ( )
{
2015-07-13 15:17:41 +01:00
bool result = KConfigDialog : : hasChanged ( ) ;
2010-03-21 10:50:44 +00:00
2015-07-13 15:17:41 +01:00
KConfigSkeletonItem * kcItem = Config : : self ( ) - > findItem ( QStringLiteral ( " defaultFileSystem " ) ) ;
result = result | | ! kcItem - > isEqual ( generalPageWidget ( ) . defaultFileSystem ( ) ) ;
result = result | | ( generalPageWidget ( ) . kcfg_shredSource - > checkedId ( ) ! = Config : : shredSource ( ) ) ;
2010-03-21 10:50:44 +00:00
2015-07-13 15:17:41 +01:00
if ( advancedPageWidget ( ) . isVisible ( ) ) {
kcItem = Config : : self ( ) - > findItem ( QStringLiteral ( " backend " ) ) ;
result = result | | ! kcItem - > isEqual ( advancedPageWidget ( ) . backend ( ) ) ;
}
2010-03-21 10:50:44 +00:00
2015-07-13 15:17:41 +01:00
return result ;
2010-03-11 19:40:42 +00:00
}
bool ConfigureOptionsDialog : : isDefault ( )
{
2015-07-13 15:17:41 +01:00
bool result = KConfigDialog : : isDefault ( ) ;
2010-03-11 19:40:42 +00:00
2015-07-13 15:17:41 +01:00
if ( result ) {
const bool useDefaults = Config : : self ( ) - > useDefaults ( true ) ;
result = ! hasChanged ( ) ;
Config : : self ( ) - > useDefaults ( useDefaults ) ;
}
2010-03-11 19:40:42 +00:00
2015-07-13 15:17:41 +01:00
return result ;
2010-03-11 19:40:42 +00:00
}
void ConfigureOptionsDialog : : updateWidgetsDefault ( )
{
2015-07-13 15:17:41 +01:00
bool useDefaults = Config : : self ( ) - > useDefaults ( true ) ;
generalPageWidget ( ) . setDefaultFileSystem ( GuiHelpers : : defaultFileSystem ( ) ) ;
generalPageWidget ( ) . radioButton - > setChecked ( true ) ;
2010-06-02 21:39:25 +01:00
2015-07-13 15:17:41 +01:00
if ( advancedPageWidget ( ) . isVisible ( ) )
advancedPageWidget ( ) . setBackend ( CoreBackendManager : : defaultBackendName ( ) ) ;
2010-06-02 21:39:25 +01:00
2015-07-13 15:17:41 +01:00
Config : : self ( ) - > useDefaults ( useDefaults ) ;
2010-03-11 19:40:42 +00:00
}
2010-03-24 23:30:20 +00:00
void ConfigureOptionsDialog : : onComboBackendActivated ( int )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( advancedPageWidget ( ) . isVisible ( ) ) ;
if ( operationStack ( ) . size ( ) = = 0 | | KMessageBox : : warningContinueCancel ( this ,
xi18nc ( " @info " ,
" <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? " ) ,
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 ) {
settingsChangedSlot ( ) ;
} else
advancedPageWidget ( ) . setBackend ( CoreBackendManager : : defaultBackendName ( ) ) ;
2010-03-24 23:30:20 +00:00
}