File indexing completed on 2021-12-21 13:33:28

0001 /* vim: noexpandtab
0002  * Kscd - A simple cd player for the KDE Project
0003  *
0004  * Copyright (c) 1997 Bernd Johannes wuebben@math.cornell.edu
0005  * Copyright (c) 2002-2003 Aaron J. Seigo <aseigo@kde.org>
0006  * Copyright (c) 2004 Alexander Kern <alex.kern@gmx.de>
0007  * Copyright (c) 2003-2006 Richard Lärkäng <nouseforaname@home.se>
0008  * Copyright (c) 2008 Amine Bouchikhi <bouchikhi.amine@gmail.com>
0009  * Copyright (c) 2008 Laurent Montel <montel@kde.org>
0010  *
0011  * This program is free software; you can redistribute it and/or modify
0012  * it under the terms of the GNU General Public License as published by
0013  * the Free Software Foundation; either version 2, or (at your option)
0014  * any later version.
0015  *
0016  * This program is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0019  * GNU General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU General Public License
0022  * along with this program; if not, write to the Free Software
0023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0024  *
0025  */
0026 #include "kscd.h"
0027 #include "dbus/PlayerDBusHandler.h"
0028 #include "dbus/RootDBusHandler.h"
0029 #include "dbus/TracklistDBusHandler.h"
0030 #include <QSplashScreen>
0031 #include <QPixmap>
0032 #include <QStringList>
0033 #include <QDir>
0034 #include <QMenu>
0035 #include <QDBusConnection>
0036 #include <QDBusInterface>
0037 #include "cdplayeradaptor.h"
0038 
0039 using namespace Phonon;
0040 
0041 static const char description[] = I18N_NOOP("KDE CD player");
0042 
0043 bool stoppedByUser = true;
0044 
0045 KSCD::KSCD( QWidget *parent ) : KscdWindow(parent)
0046 {
0047     /** Hourglass */
0048     setHourglass();
0049 
0050         new CDPlayerAdaptor( this );
0051 
0052     QDBusConnection::sessionBus().registerObject(QLatin1String( "/CDPlayer" ), this);
0053 
0054 
0055     devices = new HWControler();
0056 
0057     new KsCD::PlayerDBusHandler(this);
0058     new KsCD::RootDBusHandler(this);
0059     new KsCD::TracklistDBusHandler(this);
0060 
0061     sslider = new Phonon::SeekSlider(devices->getMedia(),this);
0062 //  sslider->setMediaObject(devices->getMedia());
0063     sslider->move(m_bar->x(),m_bar->y());
0064     sslider->setMaximumWidth(m_bar->width());
0065     sslider->setMinimumWidth(m_bar->width());
0066     sslider->show();
0067 
0068     loadSettings();
0069 
0070     /** Music Brainz initialisation */
0071     m_MBManager = new MBManager();
0072     if (devices->getMedia())
0073     {
0074         m_MBManager->discLookup(devices->getMedia()->currentSource().deviceName());
0075     }
0076 
0077     setupActions();
0078     setupContextMenu();
0079 }
0080 
0081 KSCD::~KSCD()
0082 {
0083     delete devices;
0084     delete m_MBManager;
0085 }
0086 
0087 void KSCD::setupActions()
0088 {
0089     m_actions = new KActionCollection(this);
0090     m_actions->setConfigGroup(QLatin1String( "Configuration" ));
0091 
0092     m_configureShortcutsAction = m_actions->addAction(i18n("Configure Shortcuts..."));
0093     m_configureShortcutsAction->setText(i18n("Configure Shortcuts..."));
0094     addAction(m_configureShortcutsAction);
0095     //m_configureShortcutsAction->setShortcut(Qt::Key_C);
0096     connect(m_configureShortcutsAction, SIGNAL(triggered()), this, SLOT(configureShortcuts()));
0097 
0098 
0099 
0100 
0101 
0102     m_configureAction = m_actions->addAction(i18n("Configure..."));
0103     m_configureAction->setText(i18n("Configure..."));
0104     addAction(m_configureAction);
0105     connect(m_configureAction, SIGNAL(triggered()), this, SLOT(optionsPreferences()));
0106 
0107     //download info
0108     m_downloadAction = m_actions->addAction(i18n("Download Info"));
0109     m_downloadAction->setText(i18n("Download Info"));
0110     addAction(m_downloadAction);
0111     connect(m_downloadAction, SIGNAL(triggered()), this, SLOT(discLookup()));
0112 
0113     //upload info
0114     m_uploadAction = m_actions->addAction( QLatin1String( "Upload Info" ));
0115     m_uploadAction->setText(i18n("Upload Info"));
0116     addAction(m_uploadAction);
0117     connect(m_uploadAction, SIGNAL(triggered()), this, SLOT(discUpload()));
0118 
0119     //play/pause
0120     m_playPauseAction = m_actions->addAction( QLatin1String( "Play/Pause" ));
0121     m_playPauseAction->setText(i18n("Play/Pause"));
0122     m_playPauseAction->setShortcut(Qt::Key_Space);
0123     connect(m_playPauseAction, SIGNAL(triggered()), this, SLOT(playShortcut()));
0124     addAction(m_playPauseAction);
0125 
0126     //stop
0127     m_stopAction = m_actions->addAction( QLatin1String( "Stop" ));
0128     m_stopAction->setText(i18n("Stop"));
0129     addAction(m_stopAction);
0130     m_stopAction->setShortcut(Qt::CTRL + Qt::ALT + Qt::Key_V);
0131     connect(m_stopAction, SIGNAL(triggered()), devices, SLOT(stop()));
0132 
0133     //next
0134     m_nextAction = m_actions->addAction( QLatin1String( "next" ));
0135     m_nextAction->setText(i18nc( "This action allow user to pass to the following track","Next" ));
0136     addAction(m_nextAction);
0137     m_nextAction->setShortcut(Qt::Key_Right);
0138     connect(m_nextAction, SIGNAL(triggered()), devices, SLOT(nextTrack()));
0139 
0140     //previous
0141     m_previousAction = m_actions->addAction( QLatin1String( "previous" ));
0142     m_previousAction->setText(i18nc( "This action allow the user to pass to the preceding track", "Previous" ) );
0143     addAction(m_previousAction);
0144     m_previousAction->setShortcut(Qt::Key_Left);
0145     connect(m_previousAction, SIGNAL(triggered()), devices, SLOT(prevTrack()));
0146 
0147     //eject
0148     m_ejectAction = m_actions->addAction( QLatin1String( "eject" ));
0149     m_ejectAction->setText(i18nc( " This action allow to eject the inserted disc", "Eject"));
0150     addAction(m_ejectAction);
0151     m_ejectAction->setShortcut(Qt::CTRL + Qt::ALT + Qt::Key_E);
0152     connect(m_ejectAction, SIGNAL(triggered()), this, SLOT(ejectShortcut()));
0153 
0154     //volume up
0155     m_volumeUpAction = m_actions->addAction( QLatin1String( "volume_up" ));
0156     m_volumeUpAction->setText(i18n("Volume Up"));
0157     addAction(m_volumeUpAction);
0158     m_volumeUpAction->setShortcut(Qt::Key_Up);
0159     connect(m_volumeUpAction, SIGNAL(triggered()), this, SLOT(volumeUpShortcut()));
0160 
0161     //volume down
0162     m_volumeDownAction = m_actions->addAction( QLatin1String( "volume_down" ));
0163     m_volumeDownAction->setText(i18n("Volume Down"));
0164     addAction(m_volumeDownAction);
0165     m_volumeDownAction->setShortcut(Qt::Key_Down);
0166     connect(m_volumeDownAction, SIGNAL(triggered()), this, SLOT(volumeDownShortcut()));
0167 
0168     //random
0169     m_randomAction = m_actions->addAction( QLatin1String( "random" ));
0170     m_randomAction->setText(i18nc("This action allow the user to listen a random track list","Random"));
0171     addAction(m_randomAction);
0172     m_randomAction->setShortcut(Qt::CTRL + Qt:: Key_H);
0173     connect(m_randomAction, SIGNAL(triggered()), this, SLOT(randomShortcut()));
0174 
0175     //looptrack
0176     m_looptrackAction = m_actions->addAction( QLatin1String( "looptrack" ));
0177     m_looptrackAction->setText(i18n("Repeat Track"));
0178     addAction(m_looptrackAction);
0179     m_looptrackAction->setShortcut(Qt::CTRL + Qt::Key_T);
0180     connect(m_looptrackAction, SIGNAL(triggered()), this, SLOT(looptrackShortcut()));
0181 
0182     //loopdisc
0183     m_loopdiscAction = m_actions->addAction( QLatin1String( "loopdisc" ));
0184     m_loopdiscAction->setText(i18n("Repeat Album"));
0185     addAction(m_loopdiscAction);
0186     m_loopdiscAction->setShortcut(Qt::CTRL + Qt::Key_D);
0187     connect(m_loopdiscAction, SIGNAL(triggered()), this, SLOT(loopdiscShortcut()));
0188 
0189     //tracklist
0190     m_tracklistAction = m_actions->addAction( QLatin1String( "tracklist" ));
0191     m_tracklistAction->setText(i18n("Show Tracklist"));
0192     addAction(m_tracklistAction);
0193     connect(m_tracklistAction, SIGNAL(triggered()), this, SLOT(tracklistShortcut()));
0194 
0195     //mute
0196     m_muteAction = m_actions->addAction( QLatin1String( "mute" ));
0197     m_muteAction->setText(i18n("Mute/Unmute"));
0198     addAction(m_muteAction);
0199     connect(m_muteAction, SIGNAL(triggered()), this, SLOT(muteShortcut()));
0200 
0201     //minimize
0202     m_minimizeAction = m_actions->addAction( QLatin1String( "Minimize" ));
0203     m_minimizeAction->setText(i18n("Minimize"));
0204     addAction(m_minimizeAction);
0205     connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(minimizeShortcut()));
0206 
0207     //quit
0208     m_quitAction = KStandardAction::quit(this,SLOT(quitShortcut()),this);
0209 
0210     setContextMenuPolicy(Qt::CustomContextMenu);
0211 
0212 
0213 
0214     //Read saved settings
0215     m_actions->readSettings();
0216 
0217     mute = false;
0218     play = false;
0219     random = false;
0220     looptrack = false;
0221     loopdisc = false;
0222 
0223     /**
0224      * General
0225      */
0226     // Connects UI with actions triggering
0227     connect(this,SIGNAL(actionClicked(QString)), this, SLOT(actionButton(QString)));
0228     connect(this,SIGNAL(picture(QString,QString)), this, SLOT(changePicture(QString,QString)));
0229 
0230     // General connects
0231     connect(this,SIGNAL(trackClicked(int)), this, SLOT(playTrack(int)));
0232     connect(this,SIGNAL(actionVolume(qreal)), this, SLOT(changeVolume(qreal)));
0233     connect(devices,SIGNAL(currentTime(qint64)),this,SLOT(catchtime(qint64)));
0234     connect(this,SIGNAL(infoPanel(QString)),this,SLOT(panelInfo(QString)));
0235 
0236     // MB
0237     connect(m_MBManager, SIGNAL(showArtistLabel(QString&)), this, SLOT(showArtistLabel(QString&)));
0238     connect(m_MBManager, SIGNAL(discLookupFinished()), this, SLOT(discLookupFinished()));
0239 
0240     connect(devices,SIGNAL(trackChanged()),this,SLOT(restoreTrackinfoLabel()));
0241     connect(devices,SIGNAL(cdLoaded(QString)),m_MBManager,SLOT(discLookup(QString)));
0242 
0243     connect( this , SIGNAL(customContextMenuRequested(QPoint)) , SLOT(showContextMenu(QPoint)) );
0244 }
0245 
0246 void KSCD::discLookup()
0247 {
0248     m_MBManager->discLookup(devices->getMedia()->currentSource().deviceName());
0249 }
0250 
0251 void KSCD::discUpload()
0252 {
0253     m_MBManager->discUpload(devices->getMedia()->currentSource().deviceName());
0254 }
0255 
0256 void KSCD::discLookupFinished()
0257 {
0258     // If the track dialog is open, refresh it
0259     if(m_stateTrackDialog)
0260     {
0261         createTrackDialog(m_MBManager->getTrackList(), m_MBManager->getDiscInfo().Title);
0262     }
0263 }
0264 
0265 void KSCD::setupContextMenu()
0266 {
0267     contextMenu = new QMenu( this );
0268     contextMenu->addAction(m_configureShortcutsAction);
0269     contextMenu->addAction(m_configureAction);
0270     contextMenu->addSeparator();
0271     contextMenu->addAction(m_minimizeAction);
0272     contextMenu->addAction(m_quitAction);
0273 }
0274 
0275 void KSCD::showContextMenu( const QPoint &p)
0276 {
0277     contextMenu->popup( mapToGlobal ( p ) );
0278 }
0279 
0280 /**
0281  * CDDB Management
0282  */
0283 
0284 void KSCD::restoreArtistLabel()
0285 {
0286     if( devices->getCD()->isCdInserted() && devices->isDiscValid() )
0287     {
0288         QString artist, title;
0289         artist = m_MBManager->getDiscInfo().Artist;
0290         title = m_MBManager->getDiscInfo().Title;
0291         showArtistLabel(artist);
0292         showArtistAlbum(title);
0293     }
0294     else
0295     {
0296         QString empty;
0297         showArtistLabel(empty);
0298     }
0299 
0300 }
0301 
0302 void KSCD::restoreTrackinfoLabel()
0303 {
0304     QString title, length ;
0305 
0306     // If disc is inserted
0307     int currentTrack = devices->getCurrentTrack();
0308     if (devices->getCD()->isCdInserted()  && currentTrack > 0 )
0309     {
0310 
0311         title = QString::fromLatin1("%1 - ").arg(currentTrack, 2, 10, QLatin1Char('0')) ;
0312 
0313         if (m_MBManager->getTrackList().size() >= (currentTrack))
0314         {
0315             title.append(m_MBManager->getTrackList()[currentTrack-1].Title);
0316             length.append(m_MBManager->getTrackList()[currentTrack-1].Duration);
0317         }
0318 
0319         showTrackinfoLabel(title);
0320         m_popup = new TitlePopUp(this, QLatin1String( "popup" ));
0321     }
0322     else
0323     {
0324         showTrackinfoLabel(title);
0325     }
0326 }
0327 void KSCD::changeVolume(qreal value)
0328 {
0329     //kDebug()<<"changeVolume enter "<<value;
0330     devices->setVolume(value);
0331 }
0332 
0333 void KSCD::configureShortcuts()
0334 {
0335     KShortcutsDialog::configure(m_actions, KShortcutsEditor::LetterShortcutsAllowed, this, true);
0336 }
0337 
0338 void KSCD::ejectShortcut()
0339 {
0340     QString result = QLatin1String( "eject" );
0341     actionButton(result);
0342 }
0343 
0344 void KSCD::quitShortcut()
0345 {
0346     QString result = QLatin1String( "close" );
0347     actionButton(result);
0348 }
0349 
0350 void KSCD::minimizeShortcut()
0351 {
0352     QString result = QLatin1String( "minimize" );
0353     actionButton(result);
0354 }
0355 
0356 void KSCD::tracklistShortcut()
0357 {
0358     QString result = QLatin1String( "tracklist" );
0359     actionButton(result);
0360 }
0361 
0362 void KSCD::muteShortcut()
0363 {
0364     QString def = QLatin1String( "default" );
0365     if (!mute)
0366     {
0367         QString result = QLatin1String( "unmute" );
0368         actionButton(result);
0369         emit(picture(result,def));
0370         //mute = !mute;
0371     }
0372     else
0373     {
0374         QString result = QLatin1String( "mute" );
0375         actionButton(result);
0376         emit(picture(result,def));
0377         //mute = !mute;
0378     }
0379 }
0380 
0381 void KSCD::playShortcut()
0382 {
0383     QString def = QLatin1String( "default" );
0384     if (!play)
0385     {
0386         QString result = QLatin1String( "play" );
0387         actionButton(result);
0388         emit(picture(result,def));
0389         //play = !play;
0390     }
0391     else
0392     {
0393         QString result = QLatin1String( "pause" );
0394         actionButton(result);
0395         emit(picture(result,def));
0396         //play = !play;
0397     }
0398 }
0399 
0400 void KSCD::randomShortcut()
0401 {
0402     QString def = QLatin1String( "default" );
0403     if (!random)
0404     {
0405         QString result = QLatin1String( "p_random" );
0406         actionButton(result);
0407         emit(picture(result,def));
0408         emit(infoPanel(result));
0409 
0410         //random = !random;
0411     }
0412     else
0413     {
0414         QString result = QLatin1String( "random" );
0415         actionButton(result);
0416         emit(picture(result,def));
0417         emit(infoPanel(result));
0418         //random = !random;
0419     }
0420 }
0421 
0422 void KSCD::looptrackShortcut()
0423 {
0424     QString def = QLatin1String( "default" );
0425     if (!looptrack)
0426     {
0427         QString result = QLatin1String( "looptrack" );
0428         actionButton(result);
0429         emit(picture(result,def));
0430         emit(infoPanel(result));
0431 
0432         //looptrack = !looptrack;
0433     }
0434     else
0435     {
0436         QString result = QLatin1String( "loop" );
0437         actionButton(result);
0438         emit(picture(result,def));
0439         emit(infoPanel(result));
0440 
0441         //looptrack = !looptrack;
0442     }
0443 }
0444 
0445 void KSCD::loopdiscShortcut()
0446 {
0447     QString def = QLatin1String( "default" );
0448     if (!loopdisc)
0449     {
0450         QString result = QLatin1String( "loopdisc" );
0451         actionButton(result);
0452         emit(picture(result,def));
0453         emit(infoPanel(result));
0454 
0455         //loopdisc = !loopdisc;
0456     }
0457     else
0458     {
0459         QString result = QLatin1String( "loop" );
0460         actionButton(result);
0461         emit(picture(result,def));
0462         emit(infoPanel(result));
0463 
0464         //loopdisc = !loopdisc;
0465     }
0466 }
0467 
0468 void KSCD::volumeUpShortcut()
0469 {
0470     if (devices->getVolume()<=0.95)
0471     {
0472         m_volumeB->volumeShortcut(5.0);
0473     }
0474 }
0475 
0476 void KSCD::volumeDownShortcut()
0477 {
0478     if (devices->getVolume()>=0.05)
0479     {
0480         m_volumeB->volumeShortcut(-5.0);
0481     }
0482 }
0483 
0484 
0485 void KSCD::playTrack(int track)
0486 {
0487     QString result = QLatin1String( "play" );
0488     QString def = QLatin1String( "default" );
0489     kDebug()<<"playtrack enter "<<track;
0490     devices->play(track);
0491     emit(picture(result,def));
0492     restoreArtistLabel();
0493 }
0494 
0495 /**
0496  * Link IHM with actions
0497  */
0498 void KSCD::actionButton(const QString & name)
0499 {
0500 
0501     QString state = QLatin1String( "over" );
0502     QString result;
0503     if (name == QLatin1String( "play" ))
0504     {
0505         if( !devices->isDiscValid() || !devices->getCD()->isCdInserted())
0506         {
0507             QString result;
0508             if(!devices->getCD()->isCdInserted()){
0509                 result = i18n("No disc");
0510                 showArtistLabel(result);
0511             }
0512             else{
0513                 result = i18n("Invalid disc");
0514                 showArtistLabel(result);
0515             }
0516             QTimer::singleShot(2000, this, SLOT(restoreArtistLabel()));
0517         }
0518         else
0519         {
0520             if((devices->getState() == StoppedState) || (devices->getState()) == PausedState)
0521             {
0522                 kDebug()<<"time total"<<devices->getTotalTime();
0523                 devices->play();
0524 //              m_slider->stop();
0525 //              m_slider->setTotalTime(devices->getTotalTime());
0526 //              m_slider->setStep(devices->getTotalTime());
0527                 restoreTrackinfoLabel();
0528                 restoreArtistLabel();
0529             }
0530         }
0531         emit(picture(name,state));
0532         play = !play;
0533     }
0534         else if (name == QLatin1String( "pause" ))
0535     {
0536         /*if( !devices->isDiscValid() || !devices->getCD()->isCdInserted())
0537         {
0538             if(!devices->getCD()->isCdInserted())
0539                 showArtistLabel(i18n("No disc"));
0540             else
0541                 showArtistLabel(i18n("Invalid disc"));
0542             QTimer::singleShot(2000, this, SLOT(restoreArtistLabel()));
0543         }
0544         else{*/
0545             if(devices->getState() == PlayingState)
0546             {
0547                 devices->pause();
0548             }
0549         /*}*/
0550         emit(picture(name,state));
0551         play = !play;
0552     }
0553         else if (name == QLatin1String( "next" ))
0554     {
0555         if( !devices->isDiscValid() || !devices->getCD()->isCdInserted())
0556         {
0557             QString result;
0558             if(!devices->getCD()->isCdInserted()){
0559                 result = i18n("No disc");
0560                 showArtistLabel(result);
0561             }
0562             else{
0563                 result = i18n("Invalid disc");
0564                 showArtistLabel(result);
0565             }
0566             QTimer::singleShot(2000, this, SLOT(restoreArtistLabel()));
0567         }
0568         else
0569         {
0570             devices->nextTrack();
0571             restoreTrackinfoLabel();
0572             if((devices->getState() == StoppedState) || (devices->getState() == PausedState))
0573             {
0574                 devices->stop(false);
0575 //              m_slider->stop();
0576             }
0577             if ((devices->getState() == PlayingState))
0578             {
0579 //              m_slider->stop();
0580 //              m_slider->start(devices->getTotalTime());
0581                 devices->play();
0582 
0583             }
0584         }
0585         emit(picture(name,state));
0586     }
0587         else if(name == QLatin1String( "previous" ))
0588     {
0589         if( !devices->isDiscValid() || !devices->getCD()->isCdInserted())
0590         {
0591             QString result;
0592             if(!devices->getCD()->isCdInserted()){
0593                 result = i18n("No disc");
0594                 showArtistLabel(result);
0595             }
0596             else{
0597                 result = i18n("Invalid disc");
0598                 showArtistLabel(result);
0599             }
0600             QTimer::singleShot(2000, this, SLOT(restoreArtistLabel()));
0601         }
0602         else
0603         {
0604             devices->prevTrack();
0605             restoreTrackinfoLabel();
0606 
0607             if((devices->getState() == StoppedState) || (devices->getState() == PausedState))
0608             {
0609                 devices->stop(false);
0610 //              m_slider->stop();
0611             }
0612             if ((devices->getState() == PlayingState))
0613             {
0614 //              m_slider->stop();
0615                 devices->play();
0616 //              m_slider->start(devices->getTotalTime());
0617             }
0618         }
0619         emit(picture(name,state));
0620     }
0621         else if(name == QLatin1String( "stop" ))
0622     {
0623         if ((devices->getState() == PlayingState)|| (devices->getState() == PausedState))
0624         {
0625             devices->stop();
0626 //          m_slider->stop();
0627         }
0628         emit(picture(name,state));
0629     }
0630         else if (name == QLatin1String( "eject" ))
0631     {
0632         m_trackDlg->removeRowsTrackTable();
0633         devices->eject();
0634         emit(picture(name,state));
0635         if ((devices->getState() == PlayingState)|| (devices->getState() == PausedState))
0636         {
0637             devices->stop();
0638 //          m_slider->stop();
0639         }
0640     }
0641         else if (name == QLatin1String( "mute" ))
0642     {
0643         devices->mute(false);
0644         emit(picture(name,state));
0645         mute = !mute;
0646     }
0647         else if (name == QLatin1String( "unmute" ))
0648     {
0649         devices->mute(true);
0650         emit(picture(name,state));
0651         mute = !mute;
0652     }
0653         else if (name == QLatin1String( "random" ))
0654     {
0655         devices->setRandom(false);
0656         emit(picture(name,state));
0657         result = QLatin1String( "random" );
0658         emit(infoPanel(result));
0659 
0660         random = !random;
0661     }
0662         else if (name == QLatin1String( "p_random" ))
0663     {
0664         devices->setRandom(true);
0665         emit(picture(name,state));
0666         result = QLatin1String( "p_random" );
0667         emit(infoPanel(result));
0668 
0669         random = !random;
0670     }
0671         else if (name == QLatin1String( "loop" ))
0672     {
0673         devices->setLoopMode(NoLoop);
0674         emit(picture(name,state));
0675         result = QLatin1String( "loop" );
0676         emit(infoPanel(result));
0677 
0678         looptrack = false;
0679         loopdisc = false;
0680     }
0681         else if (name == QLatin1String( "looptrack" ))
0682     {
0683         devices->setLoopMode(LoopOne);
0684         emit(picture(name,state));
0685         result = QLatin1String( "looptrack" );
0686         emit(infoPanel(result));
0687 
0688         looptrack = true;
0689         loopdisc = false;
0690     }
0691         else if (name == QLatin1String( "loopdisc" ))
0692     {
0693         devices->setLoopMode(LoopAll);
0694         emit(picture(name,state));
0695         emit(infoPanel(name));
0696 
0697         loopdisc = true;
0698         looptrack = false;
0699     }
0700         else if (name == QLatin1String( "minimize" ))
0701     {
0702         showMinimized ();
0703         emit(picture(name,state));
0704     }
0705         else if (name == QLatin1String( "close" ))
0706     {
0707         close();
0708         emit(picture(name,state));
0709     }
0710         else if (name == QLatin1String( "tracklist" ))
0711     {
0712         if(m_stateTrackDialog == true)
0713         {
0714             kDebug()<<"close track window";
0715             closeTrackDialog();
0716         }
0717         else
0718         {
0719             //createTrackDialog(m_cddbManager->getTrackList(),m_cddbManager->getDiscTitle());
0720             QList<MBTrackInfo> list = m_MBManager->getTrackList();
0721             QString title(m_MBManager->getDiscInfo().Title);
0722             createTrackDialog(list,title);
0723             kDebug()<<"open track window";
0724         }
0725         QString def = QLatin1String( "default" );
0726         emit(picture(name,def));
0727     }
0728         else if (name == QLatin1String( "configure" ))
0729     {
0730         optionsPreferences();
0731     }
0732 }
0733 
0734 /**
0735  * Hourglass
0736  */
0737 void KSCD::setHourglass()
0738 {
0739     this->setCursor(Qt::WaitCursor);
0740     QTimer::singleShot(8000, this, SLOT(unsetHourglass()));
0741 }
0742 void KSCD::unsetHourglass()
0743 {
0744     this->unsetCursor();
0745 }
0746 
0747 /**
0748  * Configuration
0749  */
0750 void KSCD::writeSettings()
0751 {
0752 //  Prefs::self()->writeConfig();
0753 }
0754 
0755 void KSCD::configureKeys()
0756 {
0757     KShortcutsDialog::configure(m_actions, KShortcutsEditor::LetterShortcutsAllowed, this, true);
0758 }
0759 
0760 /**
0761  * Accessors
0762  */
0763 HWControler* KSCD::getDevices() const
0764 {
0765     return devices;
0766 }
0767 
0768 /**
0769  * Save state on session termination
0770  */
0771 bool KSCD::saveState(QSessionManager& /*sm*/)
0772 {
0773     writeSettings();
0774     KConfigGroup config(KApplication::kApplication()->sessionConfig(), i18nc("General option in the configuration dialog","General"));
0775     //config.writeEntry(i18n("Show"), isVisible());
0776     return true;
0777 }
0778 
0779 void KSCD::optionsPreferences()
0780 {
0781     if ( KConfigDialog::showDialog( i18n("Settings") ) )  {
0782             return;
0783     }
0784 
0785     //KConfigDialog didn't find an instance of this dialog, so lets create it :
0786     KConfigDialog* dialog = new KConfigDialog( this, i18n("Settings"),  Prefs::self() );
0787     // Add the General Settings page
0788     QWidget *generalSettingsDlg = new QWidget;
0789     ui_general.setupUi(generalSettingsDlg);
0790 
0791     dialog->addPage(generalSettingsDlg, i18nc("General option in the configuration dialog","General"), QLatin1String( "kscd" ));
0792 
0793     QWidget *interfaceSettingsDlg = new QWidget;
0794     ui_interface.setupUi(interfaceSettingsDlg);
0795 
0796     //Filter on the skin url combo box
0797     QString pathSkins=KStandardDirs::installPath("data") + QLatin1String( "/kscd/skin/" );
0798     QDir directory(pathSkins);
0799     QStringList filter;
0800     filter << QLatin1String( "*.svg" );
0801     directory.setNameFilters(filter);
0802     QStringList list = directory.entryList();
0803     ui_interface.kcfg_url->addItems(list);
0804 
0805     dialog->addPage(interfaceSettingsDlg, i18n("Appearance"), QLatin1String( "fill-color" ));
0806 
0807     connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(updateSettings()));
0808     dialog->setAttribute( Qt::WA_DeleteOnClose );
0809     dialog->setHelp(QString(),QLatin1String( "kscd" ));
0810     dialog->show();
0811 }
0812 
0813 void KSCD::updateSettings()
0814 {
0815     m_panel->setTextColor(Prefs::textColor());
0816     //kDebug()<<"color config:"<<Prefs::textColor();
0817     m_panel->setTextSizeFont(Prefs::textFont());
0818     //kDebug()<<"font config:"<<Prefs::textFont();
0819     devices->setEjectActivated(Prefs::ejectOnFinish());
0820     //kDebug()<<"eject setting:"<<Prefs::ejectOnFinish();
0821     m_panel->setEjectAct( Prefs::ejectOnFinish() );
0822         QString skin;
0823         if(Prefs::url().startsWith(QLatin1Char( '/' )))
0824             skin = Prefs::url();
0825         else
0826         skin = KStandardDirs::installPath("data") + QLatin1String( "kscd/skin/" ) + Prefs::url();
0827     setNewSkin( skin );
0828 }
0829 
0830 void KSCD::loadSettings()
0831 {
0832     //setNewSkin( KStandardDirs::installPath("data") + "kscd/skin/" + Prefs::url() );
0833     m_panel->setTextColor(Prefs::textColor());
0834     m_panel->setTextSizeFont(Prefs::textFont());
0835     m_panel->setEjectAct(Prefs::ejectOnFinish());
0836     devices->setEjectActivated(Prefs::ejectOnFinish());
0837 }
0838 
0839 void KSCD::catchtime(qint64 pos){
0840     setTime(pos);
0841 }
0842 
0843 /**
0844  * main()
0845  */
0846 int main( int argc, char *argv[] )
0847 {
0848     KAboutData aboutData("kscd", 0, ki18n("KsCD"),
0849                          "1.5", ki18n(description),
0850                                       KAboutData::License_GPL,
0851            ki18n("(c) 2001, Dirk Försterling\n(c) 2003, Aaron J. Seigo"));
0852     aboutData.addCredit(ki18n("Amine Bouchikhi"), ki18n("Current maintainer, Solid/Phonon Upgrade, QDBus connection"),"bouchikhi.amine@gmail.com");
0853     aboutData.addAuthor(ki18n("Aaron J. Seigo"), ki18n("Previous maintainer"), "aseigo@kde.org");
0854     aboutData.addAuthor(ki18n("Alexander Kern"),ki18n("Workman library update, CDTEXT, CDDA"), "kernalex@kde.org");
0855     aboutData.addAuthor(ki18n("Bernd Johannes Wuebben"),KLocalizedString(), "wuebben@kde.org");
0856     aboutData.addAuthor(ki18n("Dirk Försterling"), ki18n("Workman library, previous maintainer"), "milliByte@gmx.net");
0857     aboutData.addCredit(ki18n("Wilfried Huss"), ki18n("Patches galore"));
0858     aboutData.addCredit(ki18n("Steven Grimm"), ki18n("Workman library"));
0859     aboutData.addCredit(ki18n("Sven Lueppken"), ki18n("UI Work"));
0860     aboutData.addCredit(ki18n("freedb.org"), ki18n("Special thanks to freedb.org for providing a free CDDB-like CD database"), 0, "http://freedb.org");
0861 
0862     KCmdLineArgs::init( argc, argv, &aboutData );
0863 
0864     KCmdLineOptions options;
0865     options.add("s");
0866     options.add("start", ki18n("Start playing"));
0867     KCmdLineArgs::addCmdLineOptions(options);
0868     KUniqueApplication::addCmdLineOptions();
0869     KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
0870     if (!KUniqueApplication::start())
0871     {
0872             fprintf(stderr, "kscd is already running\n");
0873             if (args->count() > 0 || args->isSet("start"))
0874             {
0875                 QDBusInterface kscd(QLatin1String( "org.kde.kscd" ), QLatin1String( "/CDPlayer" ), QLatin1String( "org.kde.kscd.CDPlayer" ));
0876                 if(kscd.isValid())
0877                 {
0878                     // Forward the command line args to the running instance.
0879                     if (args->isSet("start"))
0880                     {
0881                         kscd.call(QLatin1String( "play" ));
0882                     }
0883                 }
0884                 args->clear();
0885             }
0886             exit(0);
0887     }
0888     KUniqueApplication a;
0889     KSCD *k = new KSCD();
0890     a.setTopWidget( k );
0891 
0892     k->setWindowTitle(KGlobal::caption());
0893 
0894     if (kapp->isSessionRestored())
0895     {
0896         // The user has no way to show it if it's hidden - so why start it hidden?
0897 #if 0
0898         KConfigGroup group(KApplication::kApplication()->sessionConfig(), "General");
0899         if (group.readEntry("Show", false))
0900 #endif
0901                 {
0902             k->show();
0903         }
0904     }
0905     else
0906     {
0907             k->show();
0908     }
0909     args->clear();
0910     return a.exec();
0911 }
0912 
0913 
0914 #include "kscd.moc"