Index: mythmusic/globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/globalsettings.cpp,v
retrieving revision 1.22
diff -u -d -r1.22 globalsettings.cpp
--- mythmusic/globalsettings.cpp	30 Jan 2005 16:13:13 -0000	1.22
+++ mythmusic/globalsettings.cpp	10 Apr 2005 13:42:45 -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/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	10 Apr 2005 13:42:46 -0000
@@ -364,8 +364,11 @@
 void runRipCD(void);
 
 
-void handleMedia(MythMediaDevice *) 
+void handleMedia(MythMediaDevice *)
 {
+    if (gContext->GetNumSetting("AutoPlayCD", 0))
+        runMusicPlayback();
+    else
     mythplugin_run();
 }
 
Index: mythmusic/playbackbox.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/playbackbox.cpp,v
retrieving revision 1.84
diff -u -d -r1.84 playbackbox.cpp
--- mythmusic/playbackbox.cpp	26 Mar 2005 21:08:26 -0000	1.84
+++ mythmusic/playbackbox.cpp	10 Apr 2005 13:42:46 -0000
@@ -17,16 +17,17 @@
 #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, 
+                                   QString theme_filename,
                                    PlaylistsContainer *the_playlists,
                                    AllMusic *the_music, const char *name)
 
                 : MythThemedDialog(parent, window_name, theme_filename, name)
 {
     //  A few internal variable defaults
- 
+
     input = NULL;
     output = NULL;
     decoder = NULL;
@@ -50,7 +51,11 @@
     curMeta = NULL;
     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;
@@ -189,6 +194,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;
 
@@ -207,6 +220,11 @@
         gContext->SaveSetting("RepeatMode", "none");
 }
 
+bool PlaybackBoxMusic::onMediaEvent(MythMediaDevice *pDev)
+{
+    return scan_for_cd;
+}
+
 void PlaybackBoxMusic::keyPressEvent(QKeyEvent *e)
 {
     bool handled = false;
@@ -422,14 +440,16 @@
 
     QButton *button = playlist_popup->addButton(tr("Smart playlists"), this,
                               SLOT(showSmartPlaylistDialog()));
-    
+
     QLabel *splitter = playlist_popup->addLabel(" ", MythPopupBox::Small);
     splitter->setLineWidth(2);
     splitter->setFrameShape(QFrame::HLine);
     splitter->setFrameShadow(QFrame::Sunken);
     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)
@@ -468,24 +488,33 @@
     closePlaylistPopup();
 }
 
+void PlaybackBoxMusic::fromCD()
+{
+    if (!playlist_popup)
+        return;
+
+    updatePlaylistFromCD();
+    closePlaylistPopup();
+}
+
 void PlaybackBoxMusic::showSmartPlaylistDialog()
 {
    if (!playlist_popup)
         return;
 
     closePlaylistPopup();
-    
+
     SmartPlaylistDialog dialog(gContext->GetMainWindow(), "smartplaylistdialog");
     dialog.setSmartPlaylist(curSmartPlaylistCategory, curSmartPlaylistName);
 
     int res = dialog.ExecPopup();
-    
+
     if (res > 0)
     {
         dialog.getSmartPlaylist(curSmartPlaylistCategory, curSmartPlaylistName);
         updatePlaylistFromSmartPlaylist(curSmartPlaylistCategory, curSmartPlaylistName);
-    }    
-}    
+    }
+}
 
 void PlaybackBoxMusic::byArtist()
 {
@@ -565,10 +594,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();
@@ -576,21 +675,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()
@@ -639,6 +724,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;
Index: mythmusic/playbackbox.h
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/playbackbox.h,v
retrieving revision 1.35
diff -u -d -r1.35 playbackbox.h
--- mythmusic/playbackbox.h	6 Feb 2005 06:53:58 -0000	1.35
+++ mythmusic/playbackbox.h	10 Apr 2005 13:42:46 -0000
@@ -13,6 +13,7 @@
 #include "metadata.h"
 #include "playlist.h"
 #include "editmetadata.h"
+#include "databasebox.h"
 
 class Output;
 class Decoder;
@@ -27,7 +28,7 @@
     // Now featuring a themed constructor ... YAH!!!
     //
     typedef QValueVector<int> IntVector;
-    
+
     PlaybackBoxMusic(MythMainWindow *parent, QString window_name,
                 QString theme_filename, PlaylistsContainer *the_playlists,
                 AllMusic *the_music, const char *name = 0);
@@ -40,6 +41,8 @@
     void keyPressEvent(QKeyEvent *e);
     void constructPlaylistTree();
 
+    bool onMediaEvent(MythMediaDevice *pDev);
+
   public slots:
 
     void play();
@@ -72,6 +75,8 @@
     void wipeTrackInfo();
     void toggleFullBlankVisualizer();
 
+    void occasionallyCheckCD();
+
     // popup menu
     void showMenu();
     void closePlaylistPopup();
@@ -79,11 +84,12 @@
     void byArtist();
     void byAlbum();
     void byGenre();
-    void byYear();    
+    void byYear();
+    void fromCD();
     void showSmartPlaylistDialog();
-    
+
   signals:
-  
+
     void dummy();   // debugging
 
   private:
@@ -92,6 +98,9 @@
     void updatePlaylistFromQuickPlaylist(QString whereClause);
     void updatePlaylistFromSmartPlaylist(QString category, QString name);
     void CycleVisualizer(void);
+    void updatePlaylistFromCD(void);
+
+    void postUpdate();
 
     QIODevice *input;
     AudioOutput *output;
@@ -128,6 +137,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/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	10 Apr 2005 13:42:46 -0000
@@ -16,7 +16,7 @@
     index_value = x;
     all_available_music = all_music_ptr;
     my_widget = NULL;
-    parent = NULL;    
+    parent = NULL;
     bad_reference = false;
     label = QObject::tr("Not Initialized");
     cd_flag = false;
@@ -34,11 +34,14 @@
         else if (index_value > 0) // Normal Track
             label = all_available_music->getLabel(index_value, &bad_reference);
         else if (index_value < 0)
-            label = grandparent->getPlaylistName(index_value, 
+            label = grandparent->getPlaylistName(index_value,
                                                  bad_reference);
     }
     else
     {
+        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());
Index: mythmusic/playlist.h
===================================================================
RCS file: /var/lib/mythcvs/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	10 Apr 2005 13:42:46 -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);
