Index: mythmusic/globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythmusic/mythmusic/globalsettings.cpp,v
retrieving revision 1.23
diff -u -d -r1.23 globalsettings.cpp
--- mythmusic/globalsettings.cpp	3 May 2005 07:16:40 -0000	1.23
+++ mythmusic/globalsettings.cpp	14 May 2005 20:30:08 -0000
@@ -118,6 +118,16 @@
     return gc;
 };
 
+static HostCheckBox *AutoPlayCD()
+{
+    HostCheckBox *gc = new HostCheckBox("AutoPlayCD");
+    gc->setLabel(QObject::tr("Automatically play CDs"));
+    gc->setValue(true);
+    gc->setHelpText(QObject::tr("Automatically put a new CD on the playlist and "
+                    "start playing the CD."));
+    return gc;
+};
+
 static HostCheckBox *KeyboardAccelerators()
 {
     HostCheckBox *gc = new HostCheckBox("KeyboardAccelerators");
@@ -498,6 +508,7 @@
     general->addChild(NonID3FileNameFormat());
     general->addChild(IgnoreID3Tags());
     general->addChild(AutoLookupCD());
+    general->addChild(AutoPlayCD());
     general->addChild(KeyboardAccelerators());
     addChild(general);
 
Index: mythmusic/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythmusic/mythmusic/main.cpp,v
retrieving revision 1.57
diff -u -d -r1.57 main.cpp
--- mythmusic/main.cpp	23 Feb 2005 20:41:08 -0000	1.57
+++ mythmusic/main.cpp	14 May 2005 20:30:08 -0000
@@ -366,7 +366,10 @@
 
 void handleMedia(MythMediaDevice *) 
 {
-    mythplugin_run();
+    if (gContext->GetNumSetting("AutoPlayCD", 0))
+        runMusicPlayback();
+    else
+        mythplugin_run();
 }
 
 void setupKeys(void)
Index: mythmusic/playbackbox.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythmusic/mythmusic/playbackbox.cpp,v
retrieving revision 1.86
diff -u -d -r1.86 playbackbox.cpp
--- mythmusic/playbackbox.cpp	3 May 2005 07:16:40 -0000	1.86
+++ mythmusic/playbackbox.cpp	14 May 2005 20:30:09 -0000
@@ -17,6 +17,7 @@
 #include <mythtv/mythcontext.h>
 #include <mythtv/mythwidgets.h>
 #include <mythtv/lcddevice.h>
+#include <mythtv/mythmedia.h>
 
 PlaybackBoxMusic::PlaybackBoxMusic(MythMainWindow *parent, QString window_name,
                                    QString theme_filename, 
@@ -51,6 +52,10 @@
     curSmartPlaylistCategory = "";
     curSmartPlaylistName = "";
     
+    cd_reader_thread = NULL;
+    cd_watcher = NULL;
+    scan_for_cd = gContext->GetNumSetting("AutoPlayCD", 0);
+
     // Set our pointers the playlists and the metadata containers
 
     all_playlists = the_playlists;
@@ -163,7 +168,7 @@
     bool delayOK;
     visual_mode_delay = visual_delay.toInt(&delayOK);
     if (!delayOK)
-    	visual_mode_delay = 0;
+        visual_mode_delay = 0;
     if (visual_mode_delay > 0)
     {
         visual_mode_timer->start(visual_mode_delay * 1000);
@@ -194,6 +199,14 @@
 PlaybackBoxMusic::~PlaybackBoxMusic(void)
 {
     stopAll();
+
+    if (cd_reader_thread)
+    {
+        cd_watcher->stop();
+        cd_reader_thread->wait();
+        delete cd_reader_thread;
+    }
+
     if (playlist_tree)
         delete playlist_tree;
 
@@ -214,6 +227,11 @@
         lcd->switchToTime();
 }
 
+bool PlaybackBoxMusic::onMediaEvent(MythMediaDevice *pDev)
+{
+    return scan_for_cd;
+}
+
 void PlaybackBoxMusic::keyPressEvent(QKeyEvent *e)
 {
     bool handled = false;
@@ -441,6 +459,8 @@
     splitter->setMaximumHeight((int) (5 * hmult));
     splitter->setMaximumHeight((int) (5 * hmult));
     
+    playlist_popup->addButton(tr("From CD"), this,
+                              SLOT(fromCD()));
     playlist_popup->addButton(tr("All Tracks"), this,
                               SLOT(allTracks()));
     if (curMeta)
@@ -479,6 +499,15 @@
     closePlaylistPopup();
 }
 
+void PlaybackBoxMusic::fromCD()
+{
+    if (!playlist_popup)
+        return;
+
+    updatePlaylistFromCD();
+    closePlaylistPopup();
+}
+
 void PlaybackBoxMusic::showSmartPlaylistDialog()
 {
    if (!playlist_popup)
@@ -576,10 +605,80 @@
     music_tree_list->refresh();
 }
 
+void PlaybackBoxMusic::updatePlaylistFromCD()
+{
+    if (!cd_reader_thread)
+    {
+        cd_reader_thread = new ReadCDThread(all_playlists, all_music);
+        cd_reader_thread->start();
+    }
+
+    if (!cd_watcher)
+    {
+        cd_watcher = new QTimer(this);
+        connect(cd_watcher, SIGNAL(timeout()), this, SLOT(occasionallyCheckCD()));
+        cd_watcher->start(1000);
+    }
+
+}
+
+void PlaybackBoxMusic::postUpdate()
+{
+   QValueList <int> branches_to_current_node;
+
+   if (visual_mode_delay > 0)
+       visual_mode_timer->start(visual_mode_delay * 1000);
+
+   constructPlaylistTree();
+
+   stop();
+   wipeTrackInfo();
+
+   // move to first track in list
+   branches_to_current_node.clear();
+   branches_to_current_node.append(0); //  Root node
+   branches_to_current_node.append(1); //  We're on a playlist (not "My Music")
+   branches_to_current_node.append(0); //  Active play Queue
+   music_tree_list->moveToNodesFirstChild(branches_to_current_node);
+   music_tree_list->refresh();
+}
+
+void PlaybackBoxMusic::occasionallyCheckCD()
+{
+    if (cd_reader_thread->getLock()->locked())
+        return;
+
+    if (!scan_for_cd) {
+        cd_watcher->stop();
+        delete cd_watcher;
+        cd_watcher = NULL;
+
+        cd_reader_thread->wait();
+        delete cd_reader_thread;
+        cd_reader_thread = NULL;
+    }
+
+    if (!scan_for_cd || cd_reader_thread->statusChanged())
+    {
+        all_playlists->clearCDList();
+        all_playlists->getActive()->ripOutAllCDTracksNow();
+
+        if(all_music->getCDTrackCount()) {
+            visual_mode_timer->stop();
+
+            all_playlists->getActive()->removeAllTracks();
+            all_playlists->getActive()->fillSongsFromCD();
+
+            postUpdate();
+        }
+    }
+
+    if (scan_for_cd && !cd_reader_thread->running())
+        cd_reader_thread->start();
+}
+
 void PlaybackBoxMusic::updatePlaylistFromSmartPlaylist(QString category, QString name)
 {
-    QValueList <int> branches_to_current_node;
-    
     visual_mode_timer->stop();
 
     all_playlists->getActive()->removeAllTracks();
@@ -587,21 +686,7 @@
     all_playlists->getActive()->fillSongsFromSonglist();
     all_playlists->getActive()->postLoad();
 
-    if (visual_mode_delay > 0)
-        visual_mode_timer->start(visual_mode_delay * 1000);
-
-    constructPlaylistTree();
-    
-    stop();
-    wipeTrackInfo();
-    
-    // move to first track in list
-    branches_to_current_node.clear();
-    branches_to_current_node.append(0); //  Root node
-    branches_to_current_node.append(1); //  We're on a playlist (not "My Music")
-    branches_to_current_node.append(0); //  Active play Queue
-    music_tree_list->moveToNodesFirstChild(branches_to_current_node);
-    music_tree_list->refresh();
+    postUpdate();
 }
 
 void PlaybackBoxMusic::showEditMetadataDialog()
@@ -650,6 +735,9 @@
     {
         if (tree_is_done)
         {
+            if (scan_for_cd)
+                updatePlaylistFromCD();
+
             music_tree_list->showWholeTree(show_whole_tree);
             waiting_for_playlists_timer->stop();
             QValueList <int> branches_to_current_node;
@@ -791,13 +879,13 @@
 
         // TODO: Error checking that device is opened correctly!
         output = AudioOutput::OpenAudio(adevice, 16, 2, 44100, 
-	                                 AUDIOOUTPUT_MUSIC, true );	
+                                     AUDIOOUTPUT_MUSIC, true ); 
         output->setBufferSize(outputBufferSize * 1024);
         output->SetBlocking(false);
         output->addListener(this);
         output->addListener(mainvisual);
         output->addVisual(mainvisual);
-	
+    
         startoutput = true;
 
     }
Index: mythmusic/playbackbox.h
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythmusic/mythmusic/playbackbox.h,v
retrieving revision 1.36
diff -u -d -r1.36 playbackbox.h
--- mythmusic/playbackbox.h	3 May 2005 07:16:40 -0000	1.36
+++ mythmusic/playbackbox.h	14 May 2005 20:30:09 -0000
@@ -13,6 +13,7 @@
 #include "metadata.h"
 #include "playlist.h"
 #include "editmetadata.h"
+#include "databasebox.h"
 
 class Output;
 class Decoder;
@@ -40,6 +41,8 @@
     void keyPressEvent(QKeyEvent *e);
     void constructPlaylistTree();
 
+    bool onMediaEvent(MythMediaDevice *pDev);
+
   public slots:
 
     void play();
@@ -73,6 +76,8 @@
     void toggleFullBlankVisualizer();
     void end();
 
+    void occasionallyCheckCD();
+
     // popup menu
     void showMenu();
     void closePlaylistPopup();
@@ -81,6 +86,7 @@
     void byAlbum();
     void byGenre();
     void byYear();    
+    void fromCD();
     void showSmartPlaylistDialog();
     
   signals:
@@ -93,6 +99,9 @@
     void updatePlaylistFromQuickPlaylist(QString whereClause);
     void updatePlaylistFromSmartPlaylist(QString category, QString name);
     void CycleVisualizer(void);
+    void updatePlaylistFromCD(void);
+
+    void postUpdate();
 
     QIODevice *input;
     AudioOutput *output;
@@ -129,6 +138,11 @@
     bool isplaying;
     bool lcd_volume_visible;
 
+    ReadCDThread *cd_reader_thread;
+    QTimer *cd_watcher;
+    bool cd_checking_flag;
+    bool scan_for_cd;
+
     MainVisual *mainvisual;
 
     QString visual_mode;
Index: mythmusic/playlist.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythmusic/mythmusic/playlist.cpp,v
retrieving revision 1.27
diff -u -d -r1.27 playlist.cpp
--- mythmusic/playlist.cpp	23 Feb 2005 20:41:08 -0000	1.27
+++ mythmusic/playlist.cpp	14 May 2005 20:30:09 -0000
@@ -39,7 +39,10 @@
     }
     else
     {
-        label = all_available_music->getLabel(index_value * -1, &bad_reference);
+        if(index_value < 0)
+            label = all_available_music->getLabel(index_value, &bad_reference);
+        else
+            label = all_available_music->getLabel(index_value * -1, &bad_reference);
     }
 }
 
@@ -591,6 +594,12 @@
     raw_songlist.remove(0, 2);
 }
 
+void Playlist::fillSongsFromCD()
+{
+    for(int i = 1; i <= all_available_music->getCDTrackCount(); i++)
+       addTrack(-1 * i, true, true);
+}
+
 void Playlist::fillSonglistFromSmartPlaylist(QString category, QString name)
 {
     MSqlQuery query(MSqlQuery::InitCon());
@@ -833,7 +842,7 @@
                                             (RAND_MAX + 1.0));
                     int integer_rating = (int) (4000001 - rating_value * 10000);
                     added_node->setAttribute(3, integer_rating); //  "intelligent" order
-					 }
+                     }
             }
             if(it->getValue() < 0)
             {
@@ -1385,7 +1394,7 @@
                 level_down->computeSize(child_MB, child_sec);
                 size_in_MB += child_MB;
                 size_in_sec += child_sec;
-	    }
+        }
         }
     }
 }
Index: mythmusic/playlist.h
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythmusic/mythmusic/playlist.h,v
retrieving revision 1.12
diff -u -d -r1.12 playlist.h
--- mythmusic/playlist.h	23 Feb 2005 20:41:08 -0000	1.12
+++ mythmusic/playlist.h	14 May 2005 20:30:09 -0000
@@ -75,11 +75,12 @@
 
     void describeYourself(void); //  debugging
 
-    void fillSongsFromSonglist();
+    void fillSongsFromCD();
     void fillSonglistFromSongs();
     void fillSonglistFromQuery(QString whereClause);
     void fillSonglistFromSmartPlaylist(QString category, QString name);
-    
+    void fillSongsFromSonglist();
+
     void moveTrackUpDown(bool flag, Track *the_track);
 
     bool checkTrack(int a_track_id, bool cd_flag);
