File indexing completed on 2024-05-05 04:51:38

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 
0008 #include "k3bmiscoptiontab.h"
0009 
0010 #include "k3bpluginmanager.h"
0011 #include "k3bcore.h"
0012 #include "k3bglobalsettings.h"
0013 #include "k3binteractiondialog.h"
0014 #include "k3bintmapcombobox.h"
0015 
0016 #include <KComboBox>
0017 #include <KConfig>
0018 #include <KConfigGroup>
0019 #include <KSharedConfig>
0020 #include <KLocalizedString>
0021 #include <KUrlRequester>
0022 #include <KMessageBox>
0023 
0024 #include <QDir>
0025 #include <QFileInfo>
0026 #include <QCheckBox>
0027 #include <QRadioButton>
0028 
0029 
0030 K3b::MiscOptionTab::MiscOptionTab(QWidget *parent )
0031     : QWidget(parent)
0032 {
0033     setupUi( this );
0034 
0035     m_editTempDir->setMode( KFile::Directory );
0036 
0037     m_comboActionDialogSettings->insertItem( K3b::InteractionDialog::LOAD_K3B_DEFAULTS,
0038                                              i18n("Default Settings"),
0039                                              i18n("Load the K3b Defaults at dialog startup.") );
0040     m_comboActionDialogSettings->insertItem( K3b::InteractionDialog::LOAD_SAVED_SETTINGS,
0041                                              i18n("Saved Settings"),
0042                                              i18n("Load the settings saved by the user at dialog startup.") );
0043     m_comboActionDialogSettings->insertItem( K3b::InteractionDialog::LOAD_LAST_SETTINGS,
0044                                              i18n("Last Used Settings"),
0045                                              i18n("Load the last used settings at dialog startup.") );
0046     m_comboActionDialogSettings->addGlobalWhatsThisText( i18n("K3b handles three sets of settings in action dialogs "
0047                                                               "(action dialogs include the CD Copy dialog or the Audio CD "
0048                                                               "project dialog):"),
0049                                                          i18n("One of these sets is loaded once an action dialog is opened. "
0050                                                               "This setting defines which set it will be.") );
0051 
0052     connect(m_checkSaveOnExit, &QCheckBox::stateChanged, [this]{ Q_EMIT changed(); });
0053 }
0054 
0055 
0056 K3b::MiscOptionTab::~MiscOptionTab()
0057 {
0058 }
0059 
0060 
0061 void K3b::MiscOptionTab::readSettings()
0062 {
0063     KConfigGroup c = KSharedConfig::openConfig()->group( QStringLiteral("General Options") );
0064 
0065     m_checkSaveOnExit->setChecked( c.readEntry( "ask_for_saving_changes_on_exit", true ) );
0066     m_checkShowSplash->setChecked( c.readEntry("Show splash", true) );
0067     m_checkShowProgressOSD->setChecked(c.readEntry("Show progress OSD", false));
0068     m_checkHideMainWindowWhileWriting->setChecked( c.readEntry( "hide main window while writing", false ) );
0069     m_checkKeepDialogsOpen->setChecked( c.readEntry( "keep action dialogs open", false ) );
0070     m_comboActionDialogSettings->setSelectedValue( c.readEntry( "action dialog startup settings",
0071                                                                 ( int )K3b::InteractionDialog::LOAD_SAVED_SETTINGS ) );
0072     m_checkSystemConfig->setChecked( c.readEntry( "check system config", true ) );
0073 
0074     m_editTempDir->setUrl( QUrl::fromLocalFile( k3bcore->globalSettings()->defaultTempPath() ) );
0075 
0076 //   if( c.readEntry( "Multiple Instances", "smart" ) == "smart" )
0077 //     m_radioMultipleInstancesSmart->setChecked(true);
0078 //   else
0079 //     m_radioMultipleInstancesNew->setChecked(true);
0080 }
0081 
0082 
0083 bool K3b::MiscOptionTab::saveSettings()
0084 {
0085     KConfigGroup c = KSharedConfig::openConfig()->group( QStringLiteral("General Options") );
0086 
0087     c.writeEntry( "ask_for_saving_changes_on_exit", m_checkSaveOnExit->isChecked() );
0088     c.writeEntry( "Show splash", m_checkShowSplash->isChecked() );
0089     c.writeEntry( "Show progress OSD", m_checkShowProgressOSD->isChecked() );
0090     c.writeEntry( "hide main window while writing", m_checkHideMainWindowWhileWriting->isChecked() );
0091     c.writeEntry( "keep action dialogs open", m_checkKeepDialogsOpen->isChecked() );
0092     c.writeEntry( "check system config", m_checkSystemConfig->isChecked() );
0093     c.writeEntry( "action dialog startup settings", m_comboActionDialogSettings->selectedValue() );
0094 
0095     QString tempDir = m_editTempDir->url().toLocalFile();
0096     QFileInfo fi( tempDir );
0097     
0098     if( fi.isRelative() ) {
0099         fi.setFile( fi.absoluteFilePath() );
0100     }
0101 
0102     if( !fi.exists() ) {
0103         if( KMessageBox::questionTwoActions( this,
0104                                              i18n("Folder (%1) does not exist. Create?",tempDir),
0105                                              i18n("Create Folder"),
0106                                              KGuiItem( i18n("Create") ),
0107                                              KStandardGuiItem::cancel() ) == KMessageBox::PrimaryAction ) {
0108             if( !QDir().mkpath( fi.absoluteFilePath() ) ) {
0109                 KMessageBox::error( this, i18n("Unable to create folder %1",tempDir) );
0110                 return false;
0111             }
0112         }
0113         else {
0114             // the dir does not exist and the user doesn't want to create it
0115             return false;
0116         }
0117     }
0118 
0119     if( fi.isFile() ) {
0120         KMessageBox::information( this, i18n("You specified a file for the temporary folder. "
0121                                              "K3b will use its base path as the temporary folder."),
0122                                   i18n("Warning"),
0123                                   "temp file only using base path" );
0124         fi.setFile( fi.path() );
0125     }
0126 
0127     // check for writing permission
0128     if( !fi.isWritable() ) {
0129         KMessageBox::error( this, i18n("You do not have permission to write to %1.",fi.absoluteFilePath()) );
0130         return false;
0131     }
0132     
0133 
0134     m_editTempDir->setUrl( QUrl::fromLocalFile( fi.absoluteFilePath() ) );
0135 
0136     k3bcore->globalSettings()->setDefaultTempPath( m_editTempDir->url().toLocalFile() );
0137 
0138 //   if( m_radioMultipleInstancesSmart->isChecked() )
0139 //     c.writeEntry( "Multiple Instances", "smart" );
0140 //   else
0141 //     c.writeEntry( "Multiple Instances", "always_new" );
0142 
0143     return true;
0144 }
0145 
0146 #include "moc_k3bmiscoptiontab.cpp"