1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*
SPDX-FileCopyrightText: 2003-2009 Sebastian Trueg <trueg@k3b.org>
SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "k3bexternalencodercommand.h"
#include <config-k3b.h>
#include "k3bcore.h"
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QSet>
#include <QStandardPaths>
QList<K3bExternalEncoderCommand> K3bExternalEncoderCommand::defaultCommands()
{
QList<K3bExternalEncoderCommand> commands;
// check if the lame encoding plugin has been compiled
#ifndef HAVE_LAME
if( !QStandardPaths::findExecutable( "lame" ).isEmpty() ) {
K3bExternalEncoderCommand lameCmd;
lameCmd.name = "Mp3 (Lame)";
lameCmd.extension = "mp3";
lameCmd.command = "lame "
"-r "
"--bitwidth 16 "
"--little-endian "
"-s 44.1 "
"-h "
"--tt %t "
"--ta %a "
"--tl %m "
"--ty %y "
"--tc %c "
"--tn %n "
"- %f";
commands.append( lameCmd );
}
#endif
if( !QStandardPaths::findExecutable( "flac" ).isEmpty() ) {
K3bExternalEncoderCommand flacCmd;
flacCmd.name = "Flac";
flacCmd.extension = "flac";
flacCmd.command = "flac "
"-V "
"-o %f "
"--force-raw-format "
"--endian=little "
"--channels=2 "
"--sample-rate=44100 "
"--sign=signed "
"--bps=16 "
"-T ARTIST=%a "
"-T TITLE=%t "
"-T TRACKNUMBER=%n "
"-T DATE=%y "
"-T ALBUM=%m "
"-";
commands.append( flacCmd );
}
if( !QStandardPaths::findExecutable( "mppenc" ).isEmpty() ) {
K3bExternalEncoderCommand mppCmd;
mppCmd.name = "Musepack";
mppCmd.extension = "mpc";
mppCmd.command = "mppenc "
"--standard "
"--overwrite "
"--silent "
"--artist %a "
"--title %t "
"--track %n "
"--album %m "
"--comment %c "
"--year %y "
"- "
"%f";
mppCmd.writeWaveHeader = true;
commands.append( mppCmd );
}
return commands;
}
QList<K3bExternalEncoderCommand> K3bExternalEncoderCommand::readCommands()
{
KSharedConfig::Ptr c = KSharedConfig::openConfig();
c->reparseConfiguration();
KConfigGroup grp(c, QStringLiteral("K3bExternalEncoderPlugin") );
QList<K3bExternalEncoderCommand> commands;
QSet<QString> commandNames;
QStringList cmds = grp.readEntry( "commands",QStringList() );
for( QStringList::iterator it = cmds.begin(); it != cmds.end(); ++it ) {
QStringList cmdString = grp.readEntry( "command_" + *it,QStringList() );
K3bExternalEncoderCommand cmd;
cmd.name = cmdString[0];
cmd.extension = cmdString[1];
cmd.command = cmdString[2];
for( int i = 3; i < cmdString.count(); ++i ) {
if( cmdString[i] == "swap" )
cmd.swapByteOrder = true;
else if( cmdString[i] == "wave" )
cmd.writeWaveHeader = true;
}
commands.append( cmd );
commandNames.insert( cmd.name );
}
// some defaults
QList<K3bExternalEncoderCommand> defaults = defaultCommands();
Q_FOREACH( const K3bExternalEncoderCommand& command, defaults )
{
if ( !commandNames.contains( command.name ) ) {
commands.append( command );
commandNames.insert( command.name );
}
}
return commands;
}
void K3bExternalEncoderCommand::saveCommands( const QList<K3bExternalEncoderCommand>& cmds )
{
KSharedConfig::Ptr c = KSharedConfig::openConfig();
c->reparseConfiguration();
c->deleteGroup( QStringLiteral("K3bExternalEncoderPlugin") );
KConfigGroup grp(c, QStringLiteral("K3bExternalEncoderPlugin") );
QStringList cmdNames;
foreach( const K3bExternalEncoderCommand& cmd, cmds ) {
cmdNames << cmd.name;
QStringList cmdArgs;
cmdArgs << cmd.name << cmd.extension << cmd.command;
if( cmd.swapByteOrder )
cmdArgs << "swap";
if( cmd.writeWaveHeader )
cmdArgs << "wave";
grp.writeEntry( "command_" + cmd.name, cmdArgs );
}
grp.writeEntry( "commands", cmdNames );
}
|