File indexing completed on 2024-05-05 04:49:24

0001 /****************************************************************************************
0002  * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz>                                      *
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 "TranscodingSelectConfigWidget.h"
0018 
0019 #include <QIcon>
0020 #include <KLocalizedString>
0021 
0022 using namespace Transcoding;
0023 
0024 
0025 SelectConfigWidget::SelectConfigWidget( QWidget *parent )
0026     : QComboBox( parent )
0027     , m_passedChoice( INVALID )
0028 {
0029 }
0030 
0031 void
0032 SelectConfigWidget::fillInChoices( const Configuration &savedConfiguration )
0033 {
0034     clear();
0035     addItem( QIcon::fromTheme( QStringLiteral("edit-copy") ), i18n( "Never" ), JustCopy );
0036     addItem( QIcon::fromTheme( QStringLiteral("view-choose") ), i18n( "Ask before each transfer" ), Invalid );
0037     if( savedConfiguration.isValid() )
0038     {
0039         if( !savedConfiguration.isJustCopy() )
0040         {
0041             Configuration temp = savedConfiguration;
0042             temp.setTrackSelection( Configuration::TranscodeAll );
0043             addItem( QIcon::fromTheme( QStringLiteral("audio-x-generic") ), temp.prettyName(),
0044                     TranscodeAll );
0045             temp.setTrackSelection( Configuration::TranscodeUnlessSameType );
0046             addItem( QIcon::fromTheme( QStringLiteral("audio-x-generic") ), temp.prettyName(),
0047                     TranscodeUnlessSameType );
0048             temp.setTrackSelection( Configuration::TranscodeOnlyIfNeeded );
0049             addItem( QIcon::fromTheme( QStringLiteral("audio-x-generic") ),temp.prettyName(),
0050                     TranscodeOnlyIfNeeded );
0051             setCurrentIndex( savedConfiguration.trackSelection() + 2 );
0052         }
0053     }
0054     else
0055         setCurrentIndex( count() - 1 );
0056 
0057     m_passedChoice = savedConfiguration;
0058 }
0059 
0060 Configuration
0061 SelectConfigWidget::currentChoice() const
0062 {
0063     Configuration invalid( INVALID, m_passedChoice.trackSelection() );
0064     Configuration passedChoice = m_passedChoice;
0065     if( currentIndex() < 0 )
0066         return invalid;
0067     Choice choice = Choice( itemData( currentIndex() ).toInt() );
0068     switch( choice )
0069     {
0070         case JustCopy:
0071             return Configuration( JUST_COPY );
0072         case Invalid:
0073             return invalid;
0074         case TranscodeAll:
0075             passedChoice.setTrackSelection( Configuration::TranscodeAll );
0076             return passedChoice;
0077         case TranscodeUnlessSameType:
0078             passedChoice.setTrackSelection( Configuration::TranscodeUnlessSameType );
0079             return passedChoice;
0080         case TranscodeOnlyIfNeeded:
0081             passedChoice.setTrackSelection( Configuration::TranscodeOnlyIfNeeded );
0082             return passedChoice;
0083     }
0084     return invalid;
0085 }
0086 
0087 bool
0088 SelectConfigWidget::hasChanged() const
0089 {
0090     return currentIndex() < 0 || m_passedChoice != currentChoice();
0091 }
0092