#include "optionssimple.h" #include "config.h" #include "convertpluginloader.h" #include "optionsdetailed.h" #include #include #include #include #include #include #include #include #include //#include #include // FIXME when changing the output directory, check if the profile is a user defined and set it to 'User defined', if it is // TODO hide lossless/hybrid/etc. when not available OptionsSimple::OptionsSimple( Config* _config, OptionsDetailed* _optionsDetailed, const QString &text, QWidget *parent, const char *name ) : QWidget( parent, name ) { config = _config; optionsDetailed = _optionsDetailed; // create an icon loader object for loading icons KIconLoader* iconLoader = new KIconLoader(); QGridLayout *grid = new QGridLayout( this, 3, 1, 6, 3 ); QHBoxLayout *topBox = new QHBoxLayout( ); grid->addLayout( topBox, 0, 0 ); QLabel *lQuality = new QLabel( i18n("Quality")+":", this, "lQuality" ); topBox->addWidget( lQuality, 0, Qt::AlignVCenter ); cProfile = new KComboBox( this, "cProfile" ); sProfile += i18n("Very low"); sProfile += i18n("Low"); sProfile += i18n("Medium"); sProfile += i18n("High"); sProfile += i18n("Very high"); sProfile += i18n("Lossless"); sProfile += i18n("Hybrid"); sProfile += config->getAllProfiles(); sProfile.remove( i18n("Last used") ); sProfile.remove( "Last used" ); sProfile += i18n("User defined"); cProfile->insertStringList( sProfile ); topBox->addWidget( cProfile, 0, Qt::AlignVCenter ); connect( cProfile, SIGNAL(activated(int)), this, SLOT(profileChanged()) ); connect( cProfile, SIGNAL(activated(int)), this, SLOT(somethingChanged()) ); topBox->addSpacing( 3 ); //pProfileRemove = new KToolBarButton( "editdelete", 1002, this, "pProfileRemove" ); pProfileRemove = new KPushButton( iconLoader->loadIcon("editdelete",KIcon::Small), i18n("Remove"), this, "pProfileRemove" ); pProfileRemove->hide(); QToolTip::add( pProfileRemove, i18n("Remove the selected profile") ); topBox->addWidget( pProfileRemove, 0, Qt::AlignVCenter ); connect( pProfileRemove, SIGNAL(clicked()), this, SLOT(profileRemove()) ); //pProfileInfo = new KToolBarButton( "messagebox_info", 1110, this, "pProfileInfo" ); pProfileInfo = new KPushButton( iconLoader->loadIcon("messagebox_info",KIcon::Small), i18n("Info"), this, "pProfileInfo" ); QToolTip::add( pProfileInfo, i18n("Information about the selected profile") ); topBox->addWidget( pProfileInfo, 0, Qt::AlignVCenter ); connect( pProfileInfo, SIGNAL(clicked()), this, SLOT(profileInfo()) ); topBox->addSpacing( 18 ); QLabel *lFormat = new QLabel( i18n("Output format")+":", this, "lFormat" ); topBox->addWidget( lFormat, 0, Qt::AlignVCenter ); cFormat = new KComboBox( this, "cFormat" ); topBox->addWidget( cFormat, 0, Qt::AlignVCenter ); connect( cFormat, SIGNAL(activated(int)), this, SLOT(formatChanged()) ); connect( cFormat, SIGNAL(activated(int)), this, SLOT(somethingChanged()) ); topBox->addSpacing( 3 ); //pFormatInfo = new KToolBarButton( "messagebox_info", 1111, this, "pFormatInfo" ); pFormatInfo = new KPushButton( iconLoader->loadIcon("messagebox_info",KIcon::Small), i18n("Info"), this, "pFormatInfo" ); QToolTip::add( pFormatInfo, i18n("Information about the selected file format") ); topBox->addWidget( pFormatInfo, 0, Qt::AlignVCenter ); connect( pFormatInfo, SIGNAL(clicked()), this, SLOT(formatInfo()) ); topBox->addStretch( ); QHBoxLayout *middleBox = new QHBoxLayout( ); grid->addLayout( middleBox, 1, 0 ); outputDirectory = new OutputDirectory( config, this, "outputDirectory" ); middleBox->addWidget( outputDirectory, 0, Qt::AlignVCenter ); connect( outputDirectory, SIGNAL(modeChanged(OutputDirectory::Mode)), this, SLOT(outputDirectoryModeChanged(OutputDirectory::Mode)) ); connect( outputDirectory, SIGNAL(directoryChanged(const QString&)), this, SLOT(outputDirectoryPathChanged(const QString&)) ); connect( outputDirectory, SIGNAL(modeChanged(OutputDirectory::Mode)), this, SLOT(somethingChanged()) ); connect( outputDirectory, SIGNAL(directoryChanged(const QString&)), this, SLOT(somethingChanged()) ); QHBoxLayout *bottomBox = new QHBoxLayout( ); grid->addLayout( bottomBox, 2, 0 ); QLabel *lInfo = new QLabel( text, this, "lInfo" ); lInfo->setFixedHeight( cProfile->height() ); bottomBox->addWidget( lInfo, 0, Qt::AlignVCenter | Qt::AlignLeft ); // delete the icon loader object delete iconLoader; } OptionsSimple::~OptionsSimple() { } int OptionsSimple::profileIndex( const QString &string ) { QString profile = string; if( profile == "Very low" ) profile = i18n("Very low"); else if( profile == "Low" ) profile = i18n("Low"); else if( profile == "Medium" ) profile = i18n("Medium"); else if( profile == "High" ) profile = i18n("High"); else if( profile == "Very high" ) profile = i18n("Very high"); else if( profile == "Lossless" ) profile = i18n("Lossless"); else if( profile == "Hybrid" ) profile = i18n("Hybrid"); else if( profile == "User defined" ) profile = i18n("User defined"); return sProfile.findIndex( profile ); } int OptionsSimple::formatIndex( const QString &string ) { return sFormat.findIndex( string ); } void OptionsSimple::profileInfo() { QString sProfileString = cProfile->currentText(); if( sProfileString == i18n("Very low") ) { KMessageBox::information( this, i18n("This produces sound files of a very low quality.\nThat can be useful, if you have a mobile device, where your memory cell is limited. It is not recommended to save your music in this quality without a copy with higher quality.\nIt can also be used to save audio files with voices."), i18n("Profile")+": "+sProfileString ); } else if( sProfileString == i18n("Low") ) { KMessageBox::information( this, i18n("This produces sound files of a low quality.\nThat can be useful if you habe a mobile device where your memory cell is limited. It is not recommended to save your music in this quality without a copy with higher quality."), i18n("Profile")+": "+sProfileString ); } else if( sProfileString == i18n("Medium") ) { KMessageBox::information( this, i18n("This produces sound files of a medium quality.\nIf your disc space is limited, you can use this to save your music."), i18n("Profile")+": "+sProfileString ); } else if( sProfileString == i18n("High") ) { KMessageBox::information( this, i18n("This produces sound files of a high quality.\nIf you have enough disc space available, you can use this to save your music."), i18n("Profile")+": "+sProfileString ); } else if( sProfileString == i18n("Very high") ) { KMessageBox::information( this, i18n("This produces sound files of a very high quality.\nYou should only use this, if you are a quality freak and have enough disc space available."), i18n("Profile")+": "+sProfileString ); } else if( sProfileString == i18n("Lossless") ) { KMessageBox::information( this, i18n("This produces files, that have exact the same quality as the input files.\nThis files are very big and definitely only for quality freaks."), i18n("Profile")+": "+sProfileString ); } else if( sProfileString == i18n("Hybrid") ) { KMessageBox::information( this, i18n("This produces two files. One lossy compressed playable file and one correction file.\nBoth files together result in a file that is equivalent to the input file."), i18n("Profile")+": "+sProfileString ); } else if( sProfileString == i18n("User defined") ) { KMessageBox::information( this, i18n("You can define your own profile in the \"detailed\" tab."), i18n("Profile")+": "+sProfileString ); } // else { // the info button is hidden when showing user defined profiles // KMessageBox::error( this, // i18n("This is a user defined profile."), // i18n("Profile")+": "+sProfileString ); // } } void OptionsSimple::profileRemove() { int ret = KMessageBox::questionYesNo( this, i18n("Do you really want to remove the profile: %1").arg(cProfile->currentText()), i18n("Remove profile?") ); if( ret != KMessageBox::Yes ) return; config->removeProfile( cProfile->currentText() ); sProfile.clear(); cProfile->clear(); sProfile += i18n("Very low"); sProfile += i18n("Low"); sProfile += i18n("Medium"); sProfile += i18n("High"); sProfile += i18n("Very high"); sProfile += i18n("Lossless"); sProfile += i18n("Hybrid"); sProfile += config->getAllProfiles(); sProfile.remove( i18n("Last used") ); sProfile.remove( "Last used" ); sProfile += i18n("User defined"); cProfile->insertStringList( sProfile ); profileChanged(); } void OptionsSimple::formatInfo() { QString format = cFormat->currentText(); if( format == "wav" ) { KMessageBox::information( this, i18n("

Wave is a file format, that doesn't compress it's audio data.

\n

So the quality is very high, but the file size is enormous. It is widely spread and should work with every audio player.

\nhttp://en.wikipedia.org/wiki/Wav"), i18n("File format")+": " + format, QString::null, KMessageBox::Notify | KMessageBox::AllowLink ); return; } else { KMessageBox::information( this, config->getFormatDescription(format), i18n("File format")+": " + format, QString::null, KMessageBox::Notify | KMessageBox::AllowLink ); } } void OptionsSimple::profileChanged() { QString last; ConversionOptions options = config->getProfile( cProfile->currentText() ); if( !options.encodingOptions.sFormat.isEmpty() ) { pProfileRemove->show(); pProfileInfo->hide(); last = cFormat->currentText(); cFormat->clear(); sFormat = options.encodingOptions.sFormat; cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); outputDirectory->setMode( options.outputOptions.mode ); outputDirectory->setDirectory( options.outputOptions.directory ); optionsDetailed->setCurrentOptions( options ); return; } pProfileRemove->hide(); pProfileInfo->show(); if( cProfile->currentText() == i18n("Very low") ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allLossyEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); ConvertPlugin* plugin = config->encoderForFormat( cFormat->currentText() ); if( plugin == 0 ) { // FIXME error handling //kdDebug() << "NULL POINTER: `" << "OptionsSimple::profileChanged() / Very low" << "'" << endl; return; } if( plugin->enc.lossy.quality.enabled ) { optionsDetailed->setQualityMode( i18n("Quality") ); optionsDetailed->setQuality( 20 ); } else if( plugin->enc.lossy.bitrate.abr.enabled || plugin->enc.lossy.bitrate.cbr.enabled) { optionsDetailed->setQualityMode( i18n("Bitrate") ); optionsDetailed->setQuality( 64 ); } optionsDetailed->setBitrateRangeEnabled( false ); optionsDetailed->setSamplingrateEnabled( true ); optionsDetailed->setSamplingrate( 22050 ); optionsDetailed->setChannelsEnabled( true ); optionsDetailed->setChannels( i18n("Mono") ); optionsDetailed->setReplayGainEnabled( true ); optionsDetailed->setUserOptions( config->binaries[plugin->enc.bin] + " " + plugin->enc.in_out_files ); } else if( cProfile->currentText() == i18n("Low") ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allLossyEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); ConvertPlugin* plugin = config->encoderForFormat( cFormat->currentText() ); if( plugin == 0 ) { // FIXME error handling //kdDebug() << "NULL POINTER: `" << "OptionsSimple::profileChanged() / Low" << "'" << endl; return; } if( plugin->enc.lossy.quality.enabled ) { optionsDetailed->setQualityMode( i18n("Quality") ); optionsDetailed->setQuality( 30 ); } else if( plugin->enc.lossy.bitrate.abr.enabled || plugin->enc.lossy.bitrate.cbr.enabled ) { optionsDetailed->setQualityMode( i18n("Bitrate") ); optionsDetailed->setQuality( 96 ); } optionsDetailed->setBitrateRangeEnabled( false ); optionsDetailed->setSamplingrateEnabled( true ); optionsDetailed->setSamplingrate( 22050 ); optionsDetailed->setChannelsEnabled( false ); optionsDetailed->setReplayGainEnabled( true ); optionsDetailed->setUserOptions( config->binaries[plugin->enc.bin] + " " + plugin->enc.in_out_files ); } else if( cProfile->currentText() == i18n("Medium") ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allLossyEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); ConvertPlugin* plugin = config->encoderForFormat( cFormat->currentText() ); if( plugin == 0 ) { // FIXME error handling //kdDebug() << "NULL POINTER: `" << "OptionsSimple::profileChanged() / Medium" << "'" << endl; return; } if( plugin->enc.lossy.quality.enabled ) { optionsDetailed->setQualityMode( i18n("Quality") ); optionsDetailed->setQuality( 40 ); } else if( plugin->enc.lossy.bitrate.abr.enabled || plugin->enc.lossy.bitrate.cbr.enabled ) { optionsDetailed->setQualityMode( i18n("Bitrate") ); optionsDetailed->setQuality( 192 ); } optionsDetailed->setBitrateRangeEnabled( false ); optionsDetailed->setSamplingrateEnabled( false ); optionsDetailed->setChannelsEnabled( false ); optionsDetailed->setReplayGainEnabled( true ); optionsDetailed->setUserOptions( config->binaries[plugin->enc.bin] + " " + plugin->enc.in_out_files ); } else if( cProfile->currentText() == i18n("High") ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allLossyEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); ConvertPlugin* plugin = config->encoderForFormat( cFormat->currentText() ); if( plugin == 0 ) { // FIXME error handling //kdDebug() << "NULL POINTER: `" << "OptionsSimple::profileChanged() / High" << "'" << endl; return; } if( plugin->enc.lossy.quality.enabled ) { optionsDetailed->setQualityMode( i18n("Quality") ); optionsDetailed->setQuality( 50 ); } else if( plugin->enc.lossy.bitrate.abr.enabled || plugin->enc.lossy.bitrate.cbr.enabled ) { optionsDetailed->setQualityMode( i18n("Bitrate") ); optionsDetailed->setQuality( 240 ); } optionsDetailed->setBitrateRangeEnabled( false ); optionsDetailed->setSamplingrateEnabled( false ); optionsDetailed->setChannelsEnabled( false ); optionsDetailed->setReplayGainEnabled( true ); optionsDetailed->setUserOptions( config->binaries[plugin->enc.bin] + " " + plugin->enc.in_out_files ); } else if( cProfile->currentText() == i18n("Very high") ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allLossyEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); ConvertPlugin* plugin = config->encoderForFormat( cFormat->currentText() ); if( plugin == 0 ) { // FIXME error handling //kdDebug() << "NULL POINTER: `" << "OptionsSimple::profileChanged() / Very high" << "'" << endl; return; } if( plugin->enc.lossy.quality.enabled ) { optionsDetailed->setQualityMode( i18n("Quality") ); optionsDetailed->setQuality( 60 ); } else if( plugin->enc.lossy.bitrate.abr.enabled || plugin->enc.lossy.bitrate.cbr.enabled ) { optionsDetailed->setQualityMode( i18n("Bitrate") ); optionsDetailed->setQuality( 320 ); } optionsDetailed->setBitrateRangeEnabled( false ); optionsDetailed->setSamplingrateEnabled( false ); optionsDetailed->setChannelsEnabled( false ); optionsDetailed->setReplayGainEnabled( true ); optionsDetailed->setUserOptions( config->binaries[plugin->enc.bin] + " " + plugin->enc.in_out_files ); } else if( cProfile->currentText() == i18n("Lossless") ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allLosslessEncodableFormats(); sFormat += "wav"; cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); optionsDetailed->setReplayGainEnabled( true ); ConvertPlugin* plugin = config->encoderForFormat( cFormat->currentText() ); if( plugin != 0 ) { optionsDetailed->setUserOptions( config->binaries[plugin->enc.bin] + " " + plugin->enc.in_out_files ); } } else if( cProfile->currentText() == i18n("Hybrid")/* || cProfile->currentText() == "Hybrid"*/ ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allHybridEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); optionsDetailed->setReplayGainEnabled( true ); ConvertPlugin* plugin = config->encoderForFormat( cFormat->currentText() ); optionsDetailed->setQualityMode( i18n("Hybrid") ); if( plugin != 0 ) { optionsDetailed->setUserOptions( config->binaries[plugin->enc.bin] + " " + plugin->enc.in_out_files ); } } else if( cProfile->currentText() == i18n("User defined") ) { last = cFormat->currentText(); cFormat->clear(); sFormat = config->allEncodableFormats(); sFormat += "wav"; cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(last) ); formatChanged(); } } void OptionsSimple::formatChanged() { optionsDetailed->setFormat( cFormat->currentText() ); } void OptionsSimple::outputDirectoryModeChanged( OutputDirectory::Mode mode ) { optionsDetailed->setOutputDirectoryMode( mode ); if( cProfile->currentText() != i18n("User defined") && config->getAllProfiles().findIndex(cProfile->currentText()) != -1 ) { ConversionOptions options = config->getProfile( cProfile->currentText() ); // if( options.encodingOptions.sFormat.isEmpty() ) return; if( outputDirectory->mode() != options.outputOptions.mode || outputDirectory->directory() != options.outputOptions.directory ) { cProfile->setCurrentItem( profileIndex(i18n("User defined")) ); // NOTE not refill() ? profileChanged(); } // refill(); } } void OptionsSimple::outputDirectoryPathChanged( const QString& path ) { optionsDetailed->setOutputDirectoryPath( path ); if( cProfile->currentText() != i18n("User defined") && config->getAllProfiles().findIndex(cProfile->currentText()) != -1 ) { ConversionOptions options = config->getProfile( cProfile->currentText() ); // if( options.encodingOptions.sFormat.isEmpty() ) return; if( outputDirectory->mode() != options.outputOptions.mode || outputDirectory->directory() != options.outputOptions.directory ) { cProfile->setCurrentItem( profileIndex(i18n("User defined")) ); // NOTE not refill() ? profileChanged(); } // refill(); } } void OptionsSimple::setCurrentProfile( const QString& profile ) { // TODO check profile (and don't change, if not available) cProfile->setCurrentItem( profileIndex(profile) ); profileChanged(); } void OptionsSimple::setCurrentFormat( const QString& format ) { cFormat->setCurrentItem( formatIndex(format) ); formatChanged(); } // TODO check for errors void OptionsSimple::setCurrentOutputDirectory( const QString& directory ) { outputDirectory->setMode( OutputDirectory::Specify ); outputDirectory->setDirectory( directory ); optionsDetailed->setOutputDirectoryMode( OutputDirectory::Specify ); optionsDetailed->setOutputDirectoryPath( directory ); } void OptionsSimple::somethingChanged() { emit optionsChanged(); } void OptionsSimple::refill() { sProfile.clear(); cProfile->clear(); sProfile += i18n("Very low"); sProfile += i18n("Low"); sProfile += i18n("Medium"); sProfile += i18n("High"); sProfile += i18n("Very high"); sProfile += i18n("Lossless"); sProfile += i18n("Hybrid"); sProfile += config->getAllProfiles(); sProfile.remove( i18n("Last used") ); sProfile.remove( "Last used" ); sProfile += i18n("User defined"); cProfile->insertStringList( sProfile ); cProfile->setCurrentItem( profileIndex(config->getProfileName(optionsDetailed->getCurrentOptions())) ); if( cProfile->currentText() == i18n("Very low") || cProfile->currentText() == i18n("Low") || cProfile->currentText() == i18n("Medium") || cProfile->currentText() == i18n("High") || cProfile->currentText() == i18n("Very high") ) { cFormat->clear(); sFormat = config->allLossyEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(optionsDetailed->getFormat()) ); pProfileInfo->show(); pProfileRemove->hide(); } else if( cProfile->currentText() == i18n("Lossless") ) { cFormat->clear(); sFormat = config->allLosslessEncodableFormats(); sFormat += "wav"; cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(optionsDetailed->getFormat()) ); pProfileInfo->show(); pProfileRemove->hide(); } else if( cProfile->currentText() == i18n("Hybrid") ) { cFormat->clear(); sFormat = config->allHybridEncodableFormats(); cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(optionsDetailed->getFormat()) ); pProfileInfo->show(); pProfileRemove->hide(); } else if( cProfile->currentText() == i18n("User defined") ) { cFormat->clear(); sFormat = config->allEncodableFormats(); sFormat += "wav"; cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(optionsDetailed->getFormat()) ); pProfileInfo->show(); pProfileRemove->hide(); } else { ConversionOptions options = config->getProfile( cProfile->currentText() ); cFormat->clear(); sFormat = options.encodingOptions.sFormat; cFormat->insertStringList( sFormat ); cFormat->setCurrentItem( formatIndex(optionsDetailed->getFormat()) ); pProfileInfo->hide(); pProfileRemove->show(); } outputDirectory->setMode( optionsDetailed->getOutputDirectoryMode() ); outputDirectory->setDirectory( optionsDetailed->getOutputDirectoryPath() ); }