1 2 #include "soundkonverterapp.h" 3 #include "soundkonverter.h" 4 5 #include <KCmdLineArgs> 6 #include <KStandardDirs> 7 #include <KUrl> 8 #include <QFile> 9 10 11 soundKonverterApp::soundKonverterApp() 12 : KUniqueApplication() 13 { 14 mainWindow = new soundKonverter(); 15 setActiveWindow( mainWindow ); 16 } 17 18 soundKonverterApp::~soundKonverterApp() 19 {} 20 21 int soundKonverterApp::newInstance() 22 { 23 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 24 static bool first = true; 25 bool visible = true; 26 bool autoclose = false; 27 bool autostart = false; 28 bool activateMainWindow = true; 29 30 if( ( first || !mainWindow->isVisible() ) && args->isSet("replaygain") && args->count() > 0 ) 31 visible = false; 32 33 autoclose = args->isSet( "autoclose" ); 34 autostart = args->isSet( "autostart" ); 35 36 const QString profile = args->getOption( "profile" ); 37 const QString format = args->getOption( "format" ); 38 const QString directory = args->getOption( "output" ); 39 const QString notifyCommand = args->getOption( "command" ); 40 const QString fileListPath = args->getOption( "file-list" ); 41 42 if( args->isSet( "invisible" ) ) 43 { 44 autoclose = true; 45 autostart = true; 46 visible = false; 47 mainWindow->showSystemTray(); 48 } 49 50 if( first && fileListPath.isEmpty() && QFile::exists(KStandardDirs::locateLocal("data","soundkonverter/filelist_autosave.xml")) ) 51 { 52 if( !visible ) 53 { 54 visible = true; 55 autoclose = false; 56 autostart = false; 57 mainWindow->show(); 58 } 59 mainWindow->show(); 60 kapp->processEvents(); 61 mainWindow->loadAutosaveFileList(); 62 } 63 else if( !fileListPath.isEmpty() && QFile::exists(fileListPath) ) 64 { 65 mainWindow->loadFileList(fileListPath); 66 } 67 68 const QString device = args->getOption( "rip" ); 69 if( !device.isEmpty() ) 70 { 71 const bool success = mainWindow->ripCd( device, profile, format, directory, notifyCommand ); 72 if( !success && first ) 73 { 74 kapp->quit(); 75 return 0; 76 } 77 } 78 79 if( visible ) 80 mainWindow->show(); 81 82 mainWindow->setAutoClose( autoclose ); 83 84 if( args->isSet( "replaygain" ) ) 85 { 86 KUrl::List urls; 87 for( int i=0; i<args->count(); i++ ) 88 { 89 urls.append( args->arg(i) ); 90 } 91 if( !urls.isEmpty() ) 92 { 93 mainWindow->addReplayGainFiles( urls ); 94 activateMainWindow = false; 95 } 96 } 97 else 98 { 99 KUrl::List urls; 100 for( int i=0; i<args->count(); i++ ) 101 { 102 urls.append( args->arg(i) ); 103 } 104 if( !urls.isEmpty() ) 105 mainWindow->addConvertFiles( urls, profile, format, directory, notifyCommand ); 106 } 107 args->clear(); 108 109 if( activateMainWindow ) 110 mainWindow->activateWindow(); 111 112 if( autostart ) 113 mainWindow->startConversion(); 114 115 if( first ) 116 mainWindow->startupChecks(); 117 118 first = false; 119 120 return 0; 121 } 122 123