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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
/*
*
* $Id: k3bapplication.cpp 430266 2005-06-30 17:48:50Z trueg $
* Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2004 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 "k3bapplication.h"
#include "k3b.h"
#include "k3bwriterspeedverificationdialog.h"
#include "k3bsplash.h"
#include "k3baudioserver.h"
#include "k3binterface.h"
#include "k3bprojectmanager.h"
#include <k3bcore.h>
#include <k3bdevicemanager.h>
#include <k3bexternalbinmanager.h>
#include <k3bdefaultexternalprograms.h>
#include <k3bglobals.h>
#include <k3bversion.h>
#include <k3bdoc.h>
#include "k3bsystemproblemdialog.h"
#include <k3bthread.h>
#include <k3bpluginmanager.h>
#include <k3bthememanager.h>
#include <k3bmsf.h>
#include <k3bmovixprogram.h>
#include <ktip.h>
#include <klocale.h>
#include <kconfig.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <dcopclient.h>
#include <kstandarddirs.h>
#include <kstartupinfo.h>
#include <kmessagebox.h>
#include <qguardedptr.h>
#include <qtimer.h>
K3bApplication::Core* K3bApplication::Core::s_k3bAppCore = 0;
K3bApplication::K3bApplication()
: KUniqueApplication(),
m_interface(0),
m_mainWindow(0),
m_needToInit(true)
{
// insert library i18n data
KGlobal::locale()->insertCatalogue( "libk3bdevice" );
KGlobal::locale()->insertCatalogue( "libk3b" );
m_core = new Core( this );
// TODO: move to K3bCore?
// from this point on available through K3bAudioServer::instance()
m_audioServer = new K3bAudioServer( this, "K3bAudioServer" );
connect( m_core, SIGNAL(initializationInfo(const QString&)),
SIGNAL(initializationInfo(const QString&)) );
connect( this, SIGNAL(shutDown()), SLOT(slotShutDown()) );
}
K3bApplication::~K3bApplication()
{
// we must not delete m_mainWindow here, QApplication takes care of it
}
void K3bApplication::init()
{
QGuardedPtr<K3bSplash> splash;
if( !isRestored() ) {
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
config()->setGroup( "General Options" );
if( config()->readBoolEntry("Show splash", true) && args->isSet( "splash" ) ) {
// we need the correct splash pic
m_core->m_themeManager->readConfig( config() );
splash = new K3bSplash( 0 );
splash->connect( this, SIGNAL(initializationInfo(const QString&)), SLOT(addInfo(const QString&)) );
// kill the splash after 5 seconds
QTimer::singleShot( 5000, splash, SLOT(close()) );
splash->show();
}
}
//
// Load device, external programs, and stuff.
//
m_core->init();
m_core->readSettings( config() );
m_core->deviceManager()->printDevices();
config()->setGroup( "General Options" );
m_audioServer->setOutputMethod( config()->readEntry( "Audio Output System", "arts" ).local8Bit() );
emit initializationInfo( i18n("Creating GUI...") );
m_mainWindow = new K3bMainWindow();
m_core->m_mainWindow = m_mainWindow;
m_interface = new K3bInterface( m_mainWindow );
dcopClient()->setDefaultObject( m_interface->objId() );
if( isRestored() ) {
// we only have one single mainwindow to restore
m_mainWindow->restore(1);
}
else {
setMainWidget( m_mainWindow );
m_mainWindow->show();
emit initializationInfo( i18n("Ready.") );
config()->setGroup( "General Options" );
//
// K3b is able to autodetect most every device feature. One exception is the writing speed
// So the first time K3b is started with some device configuration we ask the user to verify
// the writing speeds if any writers are installed
//
// To check if there is a writer whose config has not been verified yet we search for a config
// entry for every writer containing a valid writing speed entry (we changed from cd writing
// speed multiplicator to KB/s)
//
K3bVersion configVersion( config()->readEntry( "config version", "0.1" ) );
QPtrList<K3bDevice::Device> wlist( k3bcore->deviceManager()->cdWriter() );
bool needToVerify = ( configVersion < K3bVersion( 0, 10, 99 ) );
if( !needToVerify ) {
// search the config
config()->setGroup( "Devices" );
for( QPtrListIterator<K3bDevice::Device> it( k3bcore->deviceManager()->cdWriter() ); *it; ++it ) {
K3bDevice::Device* dev = *it;
QString configEntryName = dev->vendor() + " " + dev->description();
QStringList list = config()->readListEntry( configEntryName );
if( list.count() > 1 && list[1].toInt() > 175 )
wlist.removeRef( dev );
}
// the devices left in wlist are the once not verified yet
needToVerify = !wlist.isEmpty();
}
if( needToVerify && !wlist.isEmpty() ) {
if( splash )
splash->close();
K3bWriterSpeedVerificationDialog::verify( wlist, m_mainWindow );
}
config()->setGroup( "General Options" );
if( config()->readBoolEntry( "check system config", true ) ) {
emit initializationInfo( i18n("Checking System") );
K3bSystemProblemDialog::checkSystem();
}
if( processCmdLineArgs() )
KTipDialog::showTip( m_mainWindow );
emit initializationDone();
}
}
int K3bApplication::newInstance()
{
if( m_needToInit ) {
// init();
m_needToInit = false;
}
else
processCmdLineArgs();
return KUniqueApplication::newInstance();
}
bool K3bApplication::processCmdLineArgs()
{
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
bool showTips = true;
if( args->isSet( "datacd" ) ) {
// create new data project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewDataDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "audiocd" ) ) {
// create new audio project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewAudioDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "mixedcd" ) ) {
// create new audio project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewMixedDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "videocd" ) ) {
// create new audio project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewVcdDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "emovixcd" ) ) {
// create new audio project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewMovixDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "datadvd" ) ) {
// create new audio project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewDvdDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "emovixdvd" ) ) {
// create new audio project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewMovixDvdDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "videodvd" ) ) {
// create new audio project and add all arguments
K3bDoc* doc = m_mainWindow->slotNewVideoDvdDoc();
for( int i = 0; i < args->count(); i++ ) {
doc->addUrl( args->url(i) );
}
}
else if( args->isSet( "cdimage" ) ) {
showTips = false;
if( k3bcore->jobsRunning() == 0 ) {
if ( args->count() == 1 )
m_mainWindow->slotWriteCdImage( args->url(0) );
else
m_mainWindow->slotWriteCdImage();
}
}
else if( args->isSet( "dvdimage" ) ) {
showTips = false;
if( k3bcore->jobsRunning() == 0 ) {
if ( args->count() == 1 )
m_mainWindow->slotWriteDvdIsoImage( args->url(0) );
else
m_mainWindow->slotWriteDvdIsoImage();
}
}
else if( args->isSet( "image" ) && args->count() == 1 ) {
showTips = false;
if( k3bcore->jobsRunning() == 0 ) {
if( K3b::filesize( args->url(0) ) > 1000*1024*1024 )
m_mainWindow->slotWriteDvdIsoImage( args->url(0) );
else
m_mainWindow->slotWriteCdImage( args->url(0) );
}
}
else if(args->count()) {
for( int i = 0; i < args->count(); i++ ) {
m_mainWindow->openDocument( args->url(i) );
}
}
if( k3bcore->jobsRunning() == 0 ) {
if( args->isSet("copycd") ) {
showTips = false;
m_mainWindow->slotCdCopy();
}
else if( args->isSet("copydvd") ) {
showTips = false;
m_mainWindow->slotDvdCopy();
}
else if( args->isSet("erasecd") ) {
showTips = false;
m_mainWindow->slotBlankCdrw();
}
else if( args->isSet("formatdvd") ) {
showTips = false;
m_mainWindow->slotFormatDvd();
}
}
// FIXME: seems not like the right place...
if( args->isSet( "ao" ) )
if( !m_audioServer->setOutputMethod( args->getOption( "ao" ) ) )
KMessageBox::error( m_mainWindow, i18n("Could not find Audio Output plugin '%1'").arg( args->getOption("ao") ) );
args->clear();
return showTips;
}
void K3bApplication::slotShutDown()
{
K3bThread::waitUntilFinished();
}
K3bApplication::Core::Core( QObject* parent )
: K3bCore( parent )
{
s_k3bAppCore = this;
m_themeManager = new K3bThemeManager( this );
m_projectManager = new K3bProjectManager( this );
// we need the themes on startup (loading them is fast anyway :)
m_themeManager->loadThemes();
}
K3bApplication::Core::~Core()
{
}
KConfig* K3bApplication::Core::config() const
{
return kapp->config();
}
void K3bApplication::Core::init()
{
emit initializationInfo( i18n("Loading all plugins...") );
pluginManager()->loadAll();
emit initializationInfo( i18n("Searching for external programs...") );
//
// The eMovix program is a special case which is not part of
// the default programs handled by K3bCore
//
externalBinManager()->addProgram( new K3bMovixProgram() );
externalBinManager()->addProgram( new K3bNormalizeProgram() );
K3b::addTranscodePrograms( externalBinManager() );
K3b::addVcdimagerPrograms( externalBinManager() );
externalBinManager()->search();
emit initializationInfo( i18n("Scanning for CD devices...") );
if( !deviceManager()->scanBus() )
kdDebug() << "No Devices found!" << endl;
}
void K3bApplication::Core::readSettings( KConfig* cnf )
{
K3bCore::readSettings( cnf );
KConfig* c = cnf;
if( !c )
c = config();
m_themeManager->readConfig( config() );
}
void K3bApplication::Core::saveSettings( KConfig* cnf )
{
K3bCore::saveSettings( cnf );
KConfig* c = cnf;
if( !c )
c = config();
m_themeManager->saveConfig( config() );
}
void K3bApplication::Core::requestBusyInfo( const QString& text )
{
emit busyInfoRequested( text );
}
void K3bApplication::Core::requestBusyFinish()
{
emit busyFinishRequested();
}
#include "k3bapplication.moc"
|