summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/movixcd/k3bmovixprogram.cpp
blob: aa5b8a50e784a184fbfdeced58ad4e3e866960fa (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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/* 
 *
 * $Id: k3bmovixprogram.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003 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 "k3bmovixprogram.h"

#include <k3bprocess.h>

#include <kdebug.h>
#include <tdelocale.h>

#include <tqdir.h>
#include <tqfile.h>
#include <tqtextstream.h>


K3bMovixProgram::K3bMovixProgram()
  : K3bExternalProgram( "eMovix" )
{
}

bool K3bMovixProgram::scan( const TQString& p )
{
  if( p.isEmpty() )
    return false;

  TQString path = p;
  if( path[path.length()-1] != '/' )
    path.append("/");

  // first test if we have a version info (eMovix >= 0.8.0pre3)
  if( !TQFile::exists( path + "movix-version" ) )
    return false;

  K3bMovixBin* bin = 0;

  //
  // probe version and data dir
  //
  TDEProcess vp, dp;
  vp << path + "movix-version";
  dp << path + "movix-conf";
  K3bProcessOutputCollector vout( &vp ), dout( &dp );
  if( vp.start( TDEProcess::Block, TDEProcess::AllOutput ) && dp.start( TDEProcess::Block, TDEProcess::AllOutput ) ) {
    // movix-version just gives us the version number on stdout
    if( !vout.output().isEmpty() && !dout.output().isEmpty() ) {
      bin = new K3bMovixBin( this );
      bin->version = vout.output().stripWhiteSpace();
      bin->path = path;
      bin->m_movixPath = dout.output().stripWhiteSpace();
    }
  }
  else {
    kdDebug() << "(K3bMovixProgram) could not start " << path << "movix-version" << endl;
    return false;
  }

  if( bin->version >= K3bVersion( 0, 9, 0 ) )
    return scanNewEMovix( bin, path );
  else
    return scanOldEMovix( bin, path );
}


bool K3bMovixProgram::scanNewEMovix( K3bMovixBin* bin, const TQString& path )
{
  TQStringList files = bin->files();
  for( TQStringList::iterator it = files.begin();
       it != files.end(); ++it ) {
    if( (*it).contains( "isolinux.cfg" ) ) {
      bin->m_supportedBootLabels = determineSupportedBootLabels( TQStringList::split( " ", *it )[1] );
      break;
    }
  }

  // here we simply check for the movix-conf program
  if( TQFile::exists( path + "movix-conf" ) ) {
    bin->addFeature( "newfiles" );
    addBin(bin);
    return true;
  }
  else {
    delete bin;
    return false;
  }
}


bool K3bMovixProgram::scanOldEMovix( K3bMovixBin* bin, const TQString& path )
{
  //
  // first check if all necessary directories are present
  //
  TQDir dir( bin->movixDataDir() );
  TQStringList subdirs = dir.entryList( TQDir::Dirs );
  if( !subdirs.contains( "boot-messages" ) ) {
    kdDebug() << "(K3bMovixProgram) could not find subdir 'boot-messages'" << endl;
    delete bin;
    return false;
  }
  if( !subdirs.contains( "isolinux" ) ) {
    kdDebug() << "(K3bMovixProgram) could not find subdir 'isolinux'" << endl;
    delete bin;
    return false;
  }
  if( !subdirs.contains( "movix" ) ) {
    kdDebug() << "(K3bMovixProgram) could not find subdir 'movix'" << endl;
    delete bin;
    return false;
  }
  if( !subdirs.contains( "mplayer-fonts" ) ) {
    kdDebug() << "(K3bMovixProgram) could not find subdir 'mplayer-fonts'" << endl;
    delete bin;
    return false;
  }


  //
  // check if we have a version of eMovix which contains the movix-files script
  //
  if( TQFile::exists( path + "movix-files" ) ) {
    bin->addFeature( "files" );

    TDEProcess p;
    K3bProcessOutputCollector out( &p );
    p << bin->path + "movix-files";
    if( p.start( TDEProcess::Block, TDEProcess::AllOutput ) ) {
      bin->m_movixFiles = TQStringList::split( "\n", out.output() );
    }
  }

  //
  // fallback: to be compatible with 0.8.0rc2 we just add all files in the movix directory
  //
  if( bin->m_movixFiles.isEmpty() ) {
    TQDir dir( bin->movixDataDir() + "/movix" );
    bin->m_movixFiles = dir.entryList(TQDir::Files);
  }

  //
  // these files are fixed. That should not be a problem
  // since Isolinux is quite stable as far as I know.
  //
  bin->m_isolinuxFiles.append( "initrd.gz" );
  bin->m_isolinuxFiles.append( "isolinux.bin" );
  bin->m_isolinuxFiles.append( "isolinux.cfg" );
  bin->m_isolinuxFiles.append( "kernel/vmlinuz" );
  bin->m_isolinuxFiles.append( "movix.lss" );
  bin->m_isolinuxFiles.append( "movix.msg" );


  //
  // check every single necessary file :(
  //
  for( TQStringList::const_iterator it = bin->m_isolinuxFiles.begin();
       it != bin->m_isolinuxFiles.end(); ++it ) {
    if( !TQFile::exists( bin->movixDataDir() + "/isolinux/" + *it ) ) {
      kdDebug() << "(K3bMovixProgram) Could not find file " << *it << endl;
      delete bin;
      return false;
    }
  }

  //
  // now check the boot-messages languages
  //
  dir.cd( "boot-messages" );
  bin->m_supportedLanguages = dir.entryList(TQDir::Dirs);
  bin->m_supportedLanguages.remove(".");
  bin->m_supportedLanguages.remove("..");
  bin->m_supportedLanguages.remove("CVS");  // the eMovix makefile stuff seems not perfect ;)
  bin->m_supportedLanguages.prepend( i18n("default") );
  dir.cdUp();

  //
  // now check the supported mplayer-fontsets
  // FIXME: every font dir needs to contain the "font.desc" file!
  //
  dir.cd( "mplayer-fonts" );
  bin->m_supportedSubtitleFonts = dir.entryList( TQDir::Dirs );
  bin->m_supportedSubtitleFonts.remove(".");
  bin->m_supportedSubtitleFonts.remove("..");
  bin->m_supportedSubtitleFonts.remove("CVS");  // the eMovix makefile stuff seems not perfect ;)
  // new ttf fonts in 0.8.0rc2
  bin->m_supportedSubtitleFonts += dir.entryList( "*.ttf", TQDir::Files );
  bin->m_supportedSubtitleFonts.prepend( i18n("none") );
  dir.cdUp();
  
  //
  // now check the supported boot labels
  //
  dir.cd( "isolinux" );
  bin->m_supportedBootLabels = determineSupportedBootLabels( dir.filePath("isolinux.cfg") );

  //
  // This seems to be a valid eMovix installation. :)
  //

  addBin(bin);
  return true;
}


TQStringList K3bMovixProgram::determineSupportedBootLabels( const TQString& isoConfigFile ) const
{
  TQStringList list( i18n("default") );

  TQFile f( isoConfigFile );
  if( !f.open( IO_ReadOnly ) ) {
    kdDebug() << "(K3bMovixProgram) could not open file '" << f.name() << "'" << endl;
  }
  else {
    TQTextStream fs( &f );
    TQString line = fs.readLine();
    while( !line.isNull() ) {
      if( line.startsWith( "label" ) )
	list.append( line.mid( 5 ).stripWhiteSpace() );
      
      line = fs.readLine();
    }
    f.close();
  }

  return list;
}


TQString K3bMovixBin::subtitleFontDir( const TQString& font ) const
{
  if( font == i18n("none" ) )
    return "";
  else if( m_supportedSubtitleFonts.contains( font ) )
    return path + "/mplayer-fonts/" + font;
  else
    return "";
}


TQString K3bMovixBin::languageDir( const TQString& lang ) const
{
  if( lang == i18n("default") )
    return languageDir( "en" );
  else if( m_supportedLanguages.contains( lang ) )
    return path + "/boot-messages/" + lang;
  else
    return "";
}


TQStringList K3bMovixBin::supportedSubtitleFonts() const
{
  if( version >= K3bVersion( 0, 9, 0 ) )
    return TQStringList( i18n("default") ) += supported( "font" );
  else
    return m_supportedSubtitleFonts;
}


TQStringList K3bMovixBin::supportedLanguages() const
{
  if( version >= K3bVersion( 0, 9, 0 ) )
    return TQStringList( i18n("default") ) += supported( "lang" );
  else
    return m_supportedLanguages;
}


// only used for eMovix >= 0.9.0
TQStringList K3bMovixBin::supportedKbdLayouts() const
{
  return TQStringList( i18n("default") ) += supported( "kbd" );
}


// only used for eMovix >= 0.9.0
TQStringList K3bMovixBin::supportedBackgrounds() const
{
  return TQStringList( i18n("default") ) += supported( "background" );
}


// only used for eMovix >= 0.9.0
TQStringList K3bMovixBin::supportedCodecs() const
{
  return supported( "codecs" );
}


TQStringList K3bMovixBin::supported( const TQString& type ) const
{
  TDEProcess p;
  K3bProcessOutputCollector out( &p );
  p << path + "movix-conf" << "--supported=" + type;
  if( p.start( TDEProcess::Block, TDEProcess::AllOutput ) )
    return TQStringList::split( "\n", out.output() );
  else
    return TQStringList();
}


TQStringList K3bMovixBin::files( const TQString& kbd,
				const TQString& font,
				const TQString& bg,
				const TQString& lang,
				const TQStringList& codecs ) const
{
  TDEProcess p;
  K3bProcessOutputCollector out( &p );
  p << path + "movix-conf" << "--files";


  if( !kbd.isEmpty() && kbd != i18n("default") )
    p << "--kbd" << kbd;
  if( !font.isEmpty() && font != i18n("default") )
    p << "--font" << font;
  if( !bg.isEmpty() && bg != i18n("default") )
    p << "--background" << bg;
  if( !lang.isEmpty() && lang != i18n("default") )
    p << "--lang" << lang;
  if( !codecs.isEmpty() )
    p << "--codecs" << codecs.join( "," );

  if( p.start( TDEProcess::Block, TDEProcess::AllOutput ) )
    return TQStringList::split( "\n", out.output() );
  else
    return TQStringList();
}