summaryrefslogtreecommitdiffstats
path: root/plugins/encoder/external/k3bexternalencodercommand.cpp
blob: 5dcfb234b060449f55092faf928236a5b1e7d68a (plain)
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
/* 
 *
 * $Id: k3bexternalencoder.cpp 567280 2006-07-28 13:26:27Z trueg $
 * Copyright (C) 2003-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */

#include <config.h>

#include "k3bexternalencodercommand.h"

#include <k3bcore.h>

#include <kconfig.h>
#include <kstandarddirs.h>


QValueList<K3bExternalEncoderCommand> K3bExternalEncoderCommand::readCommands()
{
  KConfig* c = k3bcore->config();

  c->setGroup( "K3bExternalEncoderPlugin" );

  QValueList<K3bExternalEncoderCommand> cl;

  QStringList cmds = c->readListEntry( "commands" );
  for( QStringList::iterator it = cmds.begin(); it != cmds.end(); ++it ) {
    QStringList cmdString = c->readListEntry( "command_" + *it );
    K3bExternalEncoderCommand cmd;
    cmd.name = cmdString[0];
    cmd.extension = cmdString[1];
    cmd.command = cmdString[2];
    for( unsigned int i = 3; i < cmdString.count(); ++i ) {
      if( cmdString[i] == "swap" )
	cmd.swapByteOrder = true;
      else if( cmdString[i] == "wave" )
	cmd.writeWaveHeader = true;
    }
    cl.append(cmd);
  }

  // some defaults
  if( cmds.isEmpty() ) {
    // check if the lame encoding plugin has been compiled
#ifndef HAVE_LAME
    K3bExternalEncoderCommand lameCmd;
    lameCmd.name = "Mp3 (Lame)";
    lameCmd.extension = "mp3";
    lameCmd.command = "lame -h --tt %t --ta %a --tl %m --ty %y --tc %c - %f"; 

    cl.append( lameCmd );
#endif

    if( !KStandardDirs::findExe( "flac" ).isEmpty() ) {
      K3bExternalEncoderCommand flacCmd;
      flacCmd.name = "Flac";
      flacCmd.extension = "flac";
      flacCmd.command = "flac "
	"-V "
	"-o %f "
	"--force-raw-format "
	"--endian=big "
	"--channels=2 "
	"--sample-rate=44100 "
	"--sign=signed "
	"--bps=16 "
	"-T ARTIST=%a "
	"-T TITLE=%t "
	"-T TRACKNUMBER=%n "
	"-T DATE=%y "
	"-T ALBUM=%m "
	"-";
      
      cl.append( flacCmd );
    }

    if( !KStandardDirs::findExe( "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.swapByteOrder = true;
      mppCmd.writeWaveHeader = true;
      
      cl.append( mppCmd );
    }
  }

  return cl;
}