Index: mythmusic/globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/globalsettings.cpp,v
retrieving revision 1.22
diff -u -d -b -B -r1.22 globalsettings.cpp
--- mythmusic/globalsettings.cpp        30 Jan 2005 16:13:13 -0000      1.22
+++ mythmusic/globalsettings.cpp        1 Apr 2005 22:08:02 -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 -b -B -r1.57 main.cpp
--- mythmusic/main.cpp  23 Feb 2005 20:41:08 -0000      1.57
+++ mythmusic/main.cpp  1 Apr 2005 22:08:02 -0000
@@ -366,6 +366,9 @@

 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 -b -B -r1.84 playbackbox.cpp
--- mythmusic/playbackbox.cpp   26 Mar 2005 21:08:26 -0000      1.84
+++ mythmusic/playbackbox.cpp   1 Apr 2005 22:08:02 -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;
@@ -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;
@@ -430,6 +448,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)
@@ -468,6 +488,15 @@
     closePlaylistPopup();
 }

+void PlaybackBoxMusic::fromCD()
+{
+    if (!playlist_popup)
+        return;
+
+    updatePlaylistFromCD();
+    closePlaylistPopup();
+}
+
 void PlaybackBoxMusic::showSmartPlaylistDialog()
 {
    if (!playlist_popup)
@@ -565,6 +594,70 @@
     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::occasionallyCheckCD()
+{
+    QValueList <int> branches_to_current_node;
+
+    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()) {
+            all_playlists->getActive()->removeAllTracks();
+            all_playlists->getActive()->fillSongsFromCD();
+
+           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();
+        }
+    }
+
+    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;
@@ -639,6 +732,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 -b -B -r1.35 playbackbox.h
--- mythmusic/playbackbox.h     6 Feb 2005 06:53:58 -0000       1.35
+++ mythmusic/playbackbox.h     1 Apr 2005 22:08:02 -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();
@@ -72,6 +75,8 @@
     void wipeTrackInfo();
     void toggleFullBlankVisualizer();

+    void occasionallyCheckCD();
+
     // popup menu
     void showMenu();
     void closePlaylistPopup();
@@ -80,6 +85,7 @@
     void byAlbum();
     void byGenre();
     void byYear();
+    void fromCD();
     void showSmartPlaylistDialog();

   signals:
@@ -92,6 +98,7 @@
     void updatePlaylistFromQuickPlaylist(QString whereClause);
     void updatePlaylistFromSmartPlaylist(QString category, QString name);
     void CycleVisualizer(void);
+    void updatePlaylistFromCD(void);

     QIODevice *input;
     AudioOutput *output;
@@ -128,6 +134,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 -b -B -r1.27 playlist.cpp
--- mythmusic/playlist.cpp      23 Feb 2005 20:41:08 -0000      1.27
+++ mythmusic/playlist.cpp      3 Apr 2005 18:43:17 -0000
@@ -39,6 +39,9 @@
     }
     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 +593,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());
@@ -897,7 +906,6 @@
     //
     //  Write the CD playlist (if there's anything in it)
     //
-
 /*
     if(cd_playlist.count() > 0)
     {
@@ -909,10 +917,8 @@
         cd_node->setAttribute(1, a_counter);
         cd_node->setAttribute(2, rand());
         cd_node->setAttribute(3, rand());
-
     }
 */
-
     //
     //  Write the other playlists
     //
@@ -1101,19 +1107,16 @@
     if(active_playlist)
     {
         if(active_playlist->getID() == index)
-        {
             return active_playlist->getName();
-        }

         Playlist *a_list;
         for(a_list = all_other_playlists->last(); a_list; a_list = all_other_playlists->prev())
         {
             if (a_list->getID() * -1 == index)
-            {
                 return a_list->getName();
             }
         }
-    }
+
     cerr << "playlist.o: Asked to getPlaylistName() with an index number I couldn't find" << endl ;
     reference = true;
     return QObject::tr("Something is Wrong");
Index: mythmusic/playlist.h
===================================================================
RCS file: /var/lib/mythcvs/mythmusic/mythmusic/playlist.h,v
retrieving revision 1.12
diff -u -d -b -B -r1.12 playlist.h
--- mythmusic/playlist.h        23 Feb 2005 20:41:08 -0000      1.12
+++ mythmusic/playlist.h        1 Apr 2005 22:08:02 -0000
@@ -76,6 +76,7 @@
     void describeYourself(void); //  debugging

     void fillSongsFromSonglist();
+    void fillSongsFromCD();
     void fillSonglistFromSongs();
     void fillSonglistFromQuery(QString whereClause);
     void fillSonglistFromSmartPlaylist(QString category, QString name);
