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	27 Mar 2006 21:51:12 -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.371
diff -u -b -r1.371 settings.c
--- apps/settings.c	27 Mar 2006 21:20:35 -0000	1.371
+++ apps/settings.c	27 Mar 2006 21:51:14 -0000
@@ -574,6 +574,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.213
diff -u -b -r1.213 settings.h
--- apps/settings.h	27 Mar 2006 21:20:35 -0000	1.213
+++ apps/settings.h	27 Mar 2006 21:51:16 -0000
@@ -481,6 +481,9 @@
     bool remote_bl_filter_first_keypress; /* filter first remote keypress when remote dark? */
 #endif
 #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.246
diff -u -b -r1.246 settings_menu.c
--- apps/settings_menu.c	26 Mar 2006 11:33:42 -0000	1.246
+++ apps/settings_menu.c	27 Mar 2006 21:51:16 -0000
@@ -1511,6 +1511,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;
@@ -1540,6 +1556,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.234
diff -u -b -r1.234 english.lang
--- apps/lang/english.lang	27 Mar 2006 21:20:35 -0000	1.234
+++ apps/lang/english.lang	27 Mar 2006 21:51:17 -0000
@@ -3887,3 +3887,14 @@
 voice: "Pre-cut"
 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:
\ No newline at end of file
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	27 Mar 2006 21:51:20 -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	27 Mar 2006 21:51:20 -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	27 Mar 2006 21:51:20 -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	27 Mar 2006 21:51:20 -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
 
