Index: apps/playback.c
===================================================================
RCS file: /cvsroot/rockbox/apps/playback.c,v
retrieving revision 1.223
diff -u -b -r1.223 playback.c
--- apps/playback.c	26 Mar 2006 17:07:00 -0000	1.223
+++ apps/playback.c	29 Mar 2006 19:13:28 -0000
@@ -1796,6 +1796,9 @@
     struct event ev;
     int last_tick = 0;
     bool play_pending = false;
+#ifdef HAVE_HEADPHONE_DETECTION
+    bool phones_present = false;
+#endif
 
     /* At first initialize audio system in background. */
     playback_init();
@@ -1819,6 +1822,31 @@
             ev.data = (bool *)1;
         }
         
+#ifdef HAVE_HEADPHONE_DETECTION
+        if (global_settings.pause_phones_unplugged > 0)
+        {
+            if (headphones_inserted())
+            {
+                if (phones_present)
+                {
+                    ev.id = Q_AUDIO_PAUSE;
+                    ev.data = (void *)1;
+                    phones_present = false;
+                }
+            } else {
+                if (!phones_present)
+                {
+                    if (global_settings.pause_phones_unplugged > 1)
+                    {
+                        ev.id = Q_AUDIO_RESUME;
+                        ev.data = (void *)1;
+                    }
+                    phones_present = true;
+                }
+            }
+        }
+#endif
+
         switch (ev.id) {
             case Q_AUDIO_PLAY:
                 /* Don't start playing immediately if user is skipping tracks
Index: apps/settings.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.c,v
retrieving revision 1.374
diff -u -b -r1.374 settings.c
--- apps/settings.c	29 Mar 2006 16:21:42 -0000	1.374
+++ apps/settings.c	29 Mar 2006 19:13:29 -0000
@@ -577,6 +577,10 @@
     {8, S_O(eq_precut), 0, "eq precut", NULL },
 #endif
 
+#ifdef HAVE_HEADPHONE_DETECTION
+    {2, S_O(pause_phones_unplugged), 0, "pause on headphone unplug", NULL},
+#endif
+
     /* If values are just added to the end, no need to bump the version. */
     /* new stuff to be added at the end */
 
Index: apps/settings.h
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.h,v
retrieving revision 1.214
diff -u -b -r1.214 settings.h
--- apps/settings.h	29 Mar 2006 16:21:42 -0000	1.214
+++ apps/settings.h	29 Mar 2006 19:13:31 -0000
@@ -485,6 +485,10 @@
 #ifdef HAVE_LCD_BITMAP
     unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */
 #endif
+
+#ifdef HAVE_HEADPHONE_DETECTION
+    int pause_phones_unplugged; /* pause ipods on headphone unplug */
+#endif
 };
 
 enum optiontype { INT, BOOL };
Index: apps/settings_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings_menu.c,v
retrieving revision 1.247
diff -u -b -r1.247 settings_menu.c
--- apps/settings_menu.c	28 Mar 2006 02:00:35 -0000	1.247
+++ apps/settings_menu.c	29 Mar 2006 19:13:31 -0000
@@ -1516,6 +1516,22 @@
 }
 #endif /* HAVE_DIRCACHE */
 
+#ifdef HAVE_HEADPHONE_DETECTION
+static bool pause_phones_unplugged(void)
+{
+    static const struct opt_items names[] = {
+        { STR(LANG_OFF) },
+        { STR(LANG_PAUSE) },
+        { STR(LANG_PAUSE_PHONES_RESUME) },
+    };
+    bool ret;
+    ret=set_option( str(LANG_PAUSE_PHONES),
+                    &global_settings.pause_phones_unplugged, INT, names, 3, NULL);
+        
+    return ret;
+}
+#endif
+
 static bool playback_settings_menu(void)
 {
     int m;
@@ -1545,6 +1561,9 @@
 #endif
         { ID2P(LANG_TAGCACHE_FORCE_UPDATE), tagcache_force_update },
         { ID2P(LANG_RUNTIMEDB_ACTIVE), runtimedb },
+#ifdef HAVE_HEADPHONE_DETECTION
+        { ID2P(LANG_PAUSE_PHONES), pause_phones_unplugged},
+#endif
     };
 
     bool old_shuffle = global_settings.playlist_shuffle;
Index: apps/lang/english.lang
===================================================================
RCS file: /cvsroot/rockbox/apps/lang/english.lang,v
retrieving revision 1.235
diff -u -b -r1.235 english.lang
--- apps/lang/english.lang	29 Mar 2006 16:21:42 -0000	1.235
+++ apps/lang/english.lang	29 Mar 2006 19:13:35 -0000
@@ -3898,3 +3898,15 @@
 eng: ""
 voice: "keyboard"
 new:
+
+id: LANG_PAUSE_PHONES
+desc: Pause when headphones are unplugged
+eng: "Pause on headphone unplug"
+voice: "Pause on headphone unplug"
+new:
+
+id: LANG_PAUSE_PHONES_RESUME
+desc: Pause and Resume when headphones are unplugged
+eng: "Pause and Resume"
+voice: "Pause and Resume"
+new:
Index: firmware/drivers/button.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/button.c,v
retrieving revision 1.134
diff -u -b -r1.134 button.c
--- firmware/drivers/button.c	26 Mar 2006 22:41:58 -0000	1.134
+++ firmware/drivers/button.c	29 Mar 2006 19:13:35 -0000
@@ -1341,3 +1341,9 @@
     queue_clear(&button_queue);
 }
 
+#ifdef HAVE_HEADPHONE_DETECTION
+bool headphones_inserted(void)
+{
+    return (GPIOA_INPUT_VAL & 0x80)?false:true;
+}
+#endif
Index: firmware/export/button.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/export/button.h,v
retrieving revision 1.50
diff -u -b -r1.50 button.h
--- firmware/export/button.h	26 Mar 2006 22:20:27 -0000	1.50
+++ firmware/export/button.h	29 Mar 2006 19:13:35 -0000
@@ -55,7 +55,9 @@
 #ifdef HAS_REMOTE_BUTTON_HOLD
 bool remote_button_hold(void);
 #endif
-
+#ifdef HAVE_HEADPHONE_DETECTION
+bool headphones_inserted(void);
+#endif
 
 #define  BUTTON_NONE        0x00000000
 
Index: firmware/export/config-ipodnano.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/export/config-ipodnano.h,v
retrieving revision 1.16
diff -u -b -r1.16 config-ipodnano.h
--- firmware/export/config-ipodnano.h	19 Mar 2006 17:42:58 -0000	1.16
+++ firmware/export/config-ipodnano.h	29 Mar 2006 19:13:35 -0000
@@ -100,6 +100,9 @@
 /* Define this if you have adjustable CPU frequency */
 #define HAVE_ADJUSTABLE_CPU_FREQ
 
+/* Define this if you can detect headphones */
+#define HAVE_HEADPHONE_DETECTION
+
 #define BOOTFILE_EXT "ipod"
 #define BOOTFILE "rockbox." BOOTFILE_EXT
 
Index: firmware/export/config-ipodvideo.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/export/config-ipodvideo.h,v
retrieving revision 1.13
diff -u -b -r1.13 config-ipodvideo.h
--- firmware/export/config-ipodvideo.h	19 Mar 2006 17:42:58 -0000	1.13
+++ firmware/export/config-ipodvideo.h	29 Mar 2006 19:13:35 -0000
@@ -102,6 +102,9 @@
 /* Define this if you have adjustable CPU frequency */
 #define HAVE_ADJUSTABLE_CPU_FREQ
 
+/* Define this if you can detect headphones */
+#define HAVE_HEADPHONE_DETECTION
+
 #define BOOTFILE_EXT "ipod"
 #define BOOTFILE "rockbox." BOOTFILE_EXT
 
