File indexing completed on 2025-01-19 04:24:19

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016  
0017 #include "FormatSelectionDialog.h"
0018 
0019 #include "AudioCdCollection.h"
0020 
0021 #include <KCMultiDialog>
0022 #include <KLocalizedString>
0023 
0024 FormatSelectionDialog::FormatSelectionDialog( QWidget *parent )
0025     : QDialog( parent )
0026 {
0027     setupUi( this );
0028 
0029     connect( oggButton, &QRadioButton::toggled, this, &FormatSelectionDialog::selectionChanged );
0030     connect( flacButton,  &QRadioButton::toggled, this, &FormatSelectionDialog::selectionChanged );
0031     connect( wavButton,  &QRadioButton::toggled, this, &FormatSelectionDialog::selectionChanged );
0032     connect( mp3Button,  &QRadioButton::toggled, this, &FormatSelectionDialog::selectionChanged );
0033 
0034     connect( advancedButton,  &QRadioButton::clicked, this, &FormatSelectionDialog::showAdvancedSettings );
0035 
0036 
0037     //restore format from last time, if any.
0038     KConfigGroup config = Amarok::config("Audio CD Collection");
0039     QString format = config.readEntry( "Import Format", "ogg" );
0040 
0041     if ( format.compare( "ogg", Qt::CaseInsensitive ) == 0 )
0042         oggButton->setChecked( true );
0043     else if ( format.compare( "flac", Qt::CaseInsensitive ) == 0 )
0044         flacButton->setChecked( true );
0045     else if ( format.compare( "wav", Qt::CaseInsensitive ) == 0 )
0046         wavButton->setChecked( true );
0047     else if ( format.compare( "mp3", Qt::CaseInsensitive ) == 0 )
0048         mp3Button->setChecked( true );
0049 }
0050 
0051 
0052 FormatSelectionDialog::~FormatSelectionDialog()
0053 {
0054 }
0055 
0056 void FormatSelectionDialog::selectionChanged( bool checked )
0057 {
0058     if ( !checked )
0059         return;
0060 
0061     if( sender() == oggButton )
0062     {
0063         descriptionLabel->setText( i18n( "Ogg Vorbis is a fully free and unencumbered compressed audio format that is perfect for storing your compressed music on your computer. The sound quality is slightly better than MP3 at the same bitrate. Note that not all mobile players support the Ogg Vorbis format." ) );
0064 
0065         m_selectedFormat = Collections::AudioCdCollection::OGG;
0066     }
0067     else if( sender() == flacButton )
0068     {
0069         descriptionLabel->setText( i18n( "FLAC is a lossless compressed audio format free of any patents or license fees. It maintains perfect CD audio quality while reducing file size by about 50%. Because the filesize is much larger than Ogg Vorbis or MP3 it is not recommended if you want to transfer your music to a mobile player." ) );
0070 
0071         m_selectedFormat = Collections::AudioCdCollection::FLAC;
0072     }
0073     else if( sender() == wavButton )
0074     {
0075         descriptionLabel->setText( i18n( "WAV is a basic, uncompressed audio file format. It takes up a lot of space but maintains perfect quality. It is generally not recommended unless you know what you are doing. If you want perfect quality, use FLAC instead." ) );
0076 
0077         m_selectedFormat = Collections::AudioCdCollection::WAV;
0078     }
0079     else if( sender() == mp3Button )
0080     {
0081         descriptionLabel->setText( i18n( "MP3 is the de facto standard in compressed audio compatible with almost all mobile players. It is however non free and generally not recommended." ) );
0082 
0083         m_selectedFormat = Collections::AudioCdCollection::MP3;
0084     }
0085         
0086 }
0087 
0088 void FormatSelectionDialog::accept()
0089 {
0090 
0091     //store to config for next download:
0092 
0093     QString format;
0094     
0095     if( m_selectedFormat == Collections::AudioCdCollection::OGG )
0096         format = "ogg";
0097     else if( m_selectedFormat == Collections::AudioCdCollection::FLAC )
0098         format = "flac";
0099     else if( m_selectedFormat == Collections::AudioCdCollection::WAV )
0100         format = "wav";
0101     else if( m_selectedFormat == Collections::AudioCdCollection::MP3 )
0102         format = "mp3";
0103 
0104     KConfigGroup config = Amarok::config("Audio CD Collection");
0105     config.writeEntry( "Import Format", format );
0106     
0107     Q_EMIT formatSelected( m_selectedFormat );
0108     QDialog::accept();
0109 }
0110 
0111 void FormatSelectionDialog::showAdvancedSettings()
0112 {
0113     KCMultiDialog KCM;
0114     KCM.setWindowTitle( i18n( "Audio CD settings - Amarok" ) );
0115     KCM.addModule( "audiocd" );
0116 
0117     KCM.exec();
0118 }
0119 
0120 
0121