File indexing completed on 2024-05-12 04:51:08
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 0008 #include "k3bmovixprogram.h" 0009 #include "k3b_i18n.h" 0010 0011 #include <KProcess> 0012 0013 #include <QDebug> 0014 #include <QDir> 0015 #include <QFile> 0016 #include <QTextStream> 0017 0018 0019 K3b::MovixProgram::MovixProgram() 0020 : K3b::ExternalProgram( "eMovix" ) 0021 { 0022 } 0023 0024 0025 bool K3b::MovixProgram::scan( const QString& p ) 0026 { 0027 if( p.isEmpty() ) 0028 return false; 0029 0030 QString path = p; 0031 if( path[path.length()-1] != '/' ) 0032 path.append("/"); 0033 0034 // first test if we have a version info (eMovix >= 0.8.0pre3) 0035 if( !QFile::exists( path + "movix-version" ) ) 0036 return false; 0037 0038 K3b::MovixBin* bin = 0; 0039 0040 // 0041 // probe version and data dir 0042 // 0043 KProcess vp, dp; 0044 vp << path + "movix-version"; 0045 dp << path + "movix-conf"; 0046 vp.setOutputChannelMode( KProcess::MergedChannels ); 0047 dp.setOutputChannelMode( KProcess::MergedChannels ); 0048 vp.start(); 0049 dp.start(); 0050 if( vp.waitForFinished( -1 ) && dp.waitForFinished( -1 ) ) { 0051 QByteArray vout = vp.readAll(); 0052 QByteArray dout = dp.readAll(); 0053 // movix-version just gives us the version number on stdout 0054 if( !vout.isEmpty() && !dout.isEmpty() ) { 0055 bin = new K3b::MovixBin( *this, path ); 0056 bin->setVersion( Version( vout.trimmed() ) ); 0057 bin->m_movixPath = dout.trimmed(); 0058 } 0059 } 0060 else { 0061 qDebug() << "(K3b::MovixProgram) could not start " << path << "movix-version"; 0062 return false; 0063 } 0064 0065 if( bin && bin->version() >= K3b::Version( 0, 9, 0 ) ) 0066 return scanNewEMovix( bin, path ); 0067 else 0068 return scanOldEMovix( bin, path ); 0069 } 0070 0071 0072 bool K3b::MovixProgram::scanNewEMovix( K3b::MovixBin* bin, const QString& path ) 0073 { 0074 QStringList files = bin->files(); 0075 for( QStringList::iterator it = files.begin(); 0076 it != files.end(); ++it ) { 0077 if( (*it).contains( "isolinux.cfg" ) ) { 0078 bin->m_supportedBootLabels = determineSupportedBootLabels( QString(*it).split( ' ' )[1] ); 0079 break; 0080 } 0081 } 0082 0083 // here we simply check for the movix-conf program 0084 if( QFile::exists( path + "movix-conf" ) ) { 0085 bin->addFeature( "newfiles" ); 0086 addBin(bin); 0087 return true; 0088 } 0089 else { 0090 delete bin; 0091 return false; 0092 } 0093 } 0094 0095 0096 bool K3b::MovixProgram::scanOldEMovix( K3b::MovixBin* bin, const QString& path ) 0097 { 0098 // 0099 // first check if all necessary directories are present 0100 // 0101 if (bin == Q_NULLPTR) 0102 return false; 0103 QDir dir( bin->movixDataDir() ); 0104 QStringList subdirs = dir.entryList( QDir::Dirs ); 0105 if( !subdirs.contains( "boot-messages" ) ) { 0106 qDebug() << "(K3b::MovixProgram) could not find subdir 'boot-messages'"; 0107 delete bin; 0108 return false; 0109 } 0110 if( !subdirs.contains( "isolinux" ) ) { 0111 qDebug() << "(K3b::MovixProgram) could not find subdir 'isolinux'"; 0112 delete bin; 0113 return false; 0114 } 0115 if( !subdirs.contains( "movix" ) ) { 0116 qDebug() << "(K3b::MovixProgram) could not find subdir 'movix'"; 0117 delete bin; 0118 return false; 0119 } 0120 if( !subdirs.contains( "mplayer-fonts" ) ) { 0121 qDebug() << "(K3b::MovixProgram) could not find subdir 'mplayer-fonts'"; 0122 delete bin; 0123 return false; 0124 } 0125 0126 0127 // 0128 // check if we have a version of eMovix which contains the movix-files script 0129 // 0130 if( QFile::exists( path + "movix-files" ) ) { 0131 bin->addFeature( "files" ); 0132 0133 KProcess p; 0134 p << bin->path() + "movix-files"; 0135 p.setOutputChannelMode( KProcess::MergedChannels ); 0136 p.start(); 0137 if( p.waitForFinished( -1 ) ) { 0138 bin->m_movixFiles = QString(p.readAll()).split( '\n' ); 0139 } 0140 } 0141 0142 // 0143 // fallback: to be compatible with 0.8.0rc2 we just add all files in the movix directory 0144 // 0145 if( bin->m_movixFiles.isEmpty() ) { 0146 QDir dir( bin->movixDataDir() + "/movix" ); 0147 bin->m_movixFiles = dir.entryList(QDir::Files); 0148 } 0149 0150 // 0151 // these files are fixed. That should not be a problem 0152 // since Isolinux is quite stable as far as I know. 0153 // 0154 bin->m_isolinuxFiles.append( "initrd.gz" ); 0155 bin->m_isolinuxFiles.append( "isolinux.bin" ); 0156 bin->m_isolinuxFiles.append( "isolinux.cfg" ); 0157 bin->m_isolinuxFiles.append( "kernel/vmlinuz" ); 0158 bin->m_isolinuxFiles.append( "movix.lss" ); 0159 bin->m_isolinuxFiles.append( "movix.msg" ); 0160 0161 0162 // 0163 // check every single necessary file :( 0164 // 0165 for( QStringList::const_iterator it = bin->m_isolinuxFiles.constBegin(); 0166 it != bin->m_isolinuxFiles.constEnd(); ++it ) { 0167 if( !QFile::exists( bin->movixDataDir() + "/isolinux/" + *it ) ) { 0168 qDebug() << "(K3b::MovixProgram) Could not find file " << *it; 0169 delete bin; 0170 return false; 0171 } 0172 } 0173 0174 // 0175 // now check the boot-messages languages 0176 // 0177 dir.cd( "boot-messages" ); 0178 bin->m_supportedLanguages = dir.entryList( QDir::Dirs|QDir::NoDotAndDotDot ); 0179 bin->m_supportedLanguages.removeAll("CVS"); // the eMovix makefile stuff seems not perfect ;) 0180 bin->m_supportedLanguages.prepend( i18n("default") ); 0181 dir.cdUp(); 0182 0183 // 0184 // now check the supported mplayer-fontsets 0185 // FIXME: every font dir needs to contain the "font.desc" file! 0186 // 0187 dir.cd( "mplayer-fonts" ); 0188 bin->m_supportedSubtitleFonts = dir.entryList( QDir::Dirs|QDir::NoDotAndDotDot ); 0189 bin->m_supportedSubtitleFonts.removeAll("CVS"); // the eMovix makefile stuff seems not perfect ;) 0190 // new ttf fonts in 0.8.0rc2 0191 bin->m_supportedSubtitleFonts += dir.entryList( QStringList() << "*.ttf", QDir::Files ); 0192 bin->m_supportedSubtitleFonts.prepend( i18n("none") ); 0193 dir.cdUp(); 0194 0195 // 0196 // now check the supported boot labels 0197 // 0198 dir.cd( "isolinux" ); 0199 bin->m_supportedBootLabels = determineSupportedBootLabels( dir.filePath("isolinux.cfg") ); 0200 0201 // 0202 // This seems to be a valid eMovix installation. :) 0203 // 0204 0205 addBin(bin); 0206 return true; 0207 } 0208 0209 0210 QStringList K3b::MovixProgram::determineSupportedBootLabels( const QString& isoConfigFile ) const 0211 { 0212 QStringList list( i18n("default") ); 0213 0214 QFile f( isoConfigFile ); 0215 if( !f.open( QIODevice::ReadOnly ) ) { 0216 qDebug() << "(K3b::MovixProgram) could not open file '" << f.fileName() << "'"; 0217 } 0218 else { 0219 QTextStream fs( &f ); 0220 QString line = fs.readLine(); 0221 while( !line.isNull() ) { 0222 if( line.startsWith( "label" ) ) 0223 list.append( line.mid( 5 ).trimmed() ); 0224 0225 line = fs.readLine(); 0226 } 0227 f.close(); 0228 } 0229 0230 return list; 0231 } 0232 0233 0234 QString K3b::MovixBin::subtitleFontDir( const QString& font ) const 0235 { 0236 if( font == i18n("none" ) ) 0237 return ""; 0238 else if( m_supportedSubtitleFonts.contains( font ) ) 0239 return path() + "/mplayer-fonts/" + font; 0240 else 0241 return ""; 0242 } 0243 0244 0245 QString K3b::MovixBin::languageDir( const QString& lang ) const 0246 { 0247 if( lang == i18n("default") ) 0248 return languageDir( "en" ); 0249 else if( m_supportedLanguages.contains( lang ) ) 0250 return path() + "/boot-messages/" + lang; 0251 else 0252 return ""; 0253 } 0254 0255 0256 QStringList K3b::MovixBin::supportedSubtitleFonts() const 0257 { 0258 if( version() >= K3b::Version( 0, 9, 0 ) ) 0259 return QStringList( i18n("default") ) += supported( "font" ); 0260 else 0261 return m_supportedSubtitleFonts; 0262 } 0263 0264 0265 QStringList K3b::MovixBin::supportedLanguages() const 0266 { 0267 if( version() >= K3b::Version( 0, 9, 0 ) ) 0268 return QStringList( i18n("default") ) += supported( "lang" ); 0269 else 0270 return m_supportedLanguages; 0271 } 0272 0273 0274 // only used for eMovix >= 0.9.0 0275 QStringList K3b::MovixBin::supportedKbdLayouts() const 0276 { 0277 return QStringList( i18n("default") ) += supported( "kbd" ); 0278 } 0279 0280 0281 // only used for eMovix >= 0.9.0 0282 QStringList K3b::MovixBin::supportedBackgrounds() const 0283 { 0284 return QStringList( i18n("default") ) += supported( "background" ); 0285 } 0286 0287 0288 // only used for eMovix >= 0.9.0 0289 QStringList K3b::MovixBin::supportedCodecs() const 0290 { 0291 return supported( "codecs" ); 0292 } 0293 0294 0295 QStringList K3b::MovixBin::supported( const QString& type ) const 0296 { 0297 KProcess p; 0298 p << path() + "movix-conf" << "--supported=" + type; 0299 p.setOutputChannelMode( KProcess::MergedChannels ); 0300 p.start(); 0301 if( p.waitForFinished( -1 ) ) 0302 return QString(p.readAll()).split( '\n', Qt::SkipEmptyParts ); 0303 else 0304 return QStringList(); 0305 } 0306 0307 0308 QStringList K3b::MovixBin::files( const QString& kbd, 0309 const QString& font, 0310 const QString& bg, 0311 const QString& lang, 0312 const QStringList& codecs ) const 0313 { 0314 KProcess p; 0315 p << path() + "movix-conf" << "--files"; 0316 p.setOutputChannelMode( KProcess::MergedChannels ); 0317 0318 if( !kbd.isEmpty() && kbd != i18n("default") ) 0319 p << "--kbd" << kbd; 0320 if( !font.isEmpty() && font != i18n("default") ) 0321 p << "--font" << font; 0322 if( !bg.isEmpty() && bg != i18n("default") ) 0323 p << "--background" << bg; 0324 if( !lang.isEmpty() && lang != i18n("default") ) 0325 p << "--lang" << lang; 0326 if( !codecs.isEmpty() ) 0327 p << "--codecs" << codecs.join( "," ); 0328 0329 p.start(); 0330 if( p.waitForFinished( -1 ) ) 0331 return QString(p.readAll()).split( '\n', Qt::SkipEmptyParts ); 0332 else 0333 return QStringList(); 0334 }