Bell can now play an arbitrary sound file.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 14 Apr 2001 11:37:47 +0000 (11:37 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 14 Apr 2001 11:37:47 +0000 (11:37 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/putty@1041 cda61777-01e9-0310-a592-d414129be87e

putty.h
settings.c
windlg.c
window.c

diff --git a/putty.h b/putty.h
index b560688..2b37b17 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -217,11 +217,14 @@ typedef struct {
     int lfhascr;
     int cursor_type;                  /* 0=block 1=underline 2=vertical */
     int blink_cur;
-    int beep;                         /* 0=none 1=defaultsound 2=visual */
+    enum {
+       BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE
+    } beep;
     int bellovl;                      /* bell overload protection active? */
     int bellovl_n;                    /* number of bells to cause overload */
     int bellovl_t;                    /* time interval for overload (seconds) */
     int bellovl_s;                    /* period of silence to re-enable bell (s) */
+    char bell_wavefile[FILENAME_MAX];
     int scrollbar;
     int locksize;
     int bce;
index e1bfbc3..783d052 100644 (file)
@@ -104,6 +104,7 @@ void save_settings (char *section, int do_host, Config *cfg) {
     write_setting_i (sesskey, "CurType", cfg->cursor_type);
     write_setting_i (sesskey, "BlinkCur", cfg->blink_cur);
     write_setting_i (sesskey, "Beep", cfg->beep);
+    write_setting_s (sesskey, "BellWaveFile", cfg->bell_wavefile);
     write_setting_i (sesskey, "BellOverload", cfg->bellovl);
     write_setting_i (sesskey, "BellOverloadN", cfg->bellovl_n);
     write_setting_i (sesskey, "BellOverloadT", cfg->bellovl_t);
@@ -260,6 +261,8 @@ void load_settings (char *section, int do_host, Config *cfg) {
     gppi (sesskey, "CurType", 0, &cfg->cursor_type);
     gppi (sesskey, "BlinkCur", 0, &cfg->blink_cur);
     gppi (sesskey, "Beep", 1, &cfg->beep);
+    gpps (sesskey, "BellWaveFile", "", cfg->bell_wavefile,
+         sizeof(cfg->bell_wavefile));
     gppi (sesskey, "BellOverload", 1, &cfg->bellovl);
     gppi (sesskey, "BellOverloadN", 5, &cfg->bellovl_n);
     gppi (sesskey, "BellOverloadT", 2, &cfg->bellovl_t);
index 916a9e5..133c2d2 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -291,7 +291,11 @@ enum { IDCX_ABOUT = IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue,
     IDC_BELLSTATIC,
     IDC_BELL_DISABLED,
     IDC_BELL_DEFAULT,
+    IDC_BELL_WAVEFILE,
     IDC_BELL_VISUAL,
+    IDC_BELL_WAVESTATIC,
+    IDC_BELL_WAVEEDIT,
+    IDC_BELL_WAVEBROWSE,
     IDC_BELLOVL,
     IDC_BELLOVLNSTATIC,
     IDC_BELLOVLN,
@@ -566,8 +570,11 @@ static void init_dlg_ctrls(HWND hwnd) {
     fmtfont (fontstatic);
     SetDlgItemText (hwnd, IDC_FONTSTATIC, fontstatic);
     CheckRadioButton (hwnd, IDC_BELL_DISABLED, IDC_BELL_VISUAL,
-                     cfg.beep==0 ? IDC_BELL_DISABLED :
-                     cfg.beep==1 ? IDC_BELL_DEFAULT : IDC_BELL_VISUAL);
+                     cfg.beep==BELL_DISABLED ? IDC_BELL_DISABLED :
+                     cfg.beep==BELL_DEFAULT ? IDC_BELL_DEFAULT :
+                     cfg.beep==BELL_WAVEFILE ? IDC_BELL_WAVEFILE :
+                     cfg.beep==BELL_VISUAL ? IDC_BELL_VISUAL : IDC_BELL_DEFAULT);
+    SetDlgItemText (hwnd, IDC_BELL_WAVEEDIT, cfg.bell_wavefile);
     CheckDlgButton (hwnd, IDC_BELLOVL, cfg.bellovl);
     SetDlgItemInt (hwnd, IDC_BELLOVLN, cfg.bellovl_n, FALSE);
     SetDlgItemInt (hwnd, IDC_BELLOVLT, cfg.bellovl_t, FALSE);
@@ -808,7 +815,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
     }
 
     if (panel == bellpanelstart) {
-        /* The Bell panel. Accelerators used: [acgo] bdsm */
+        /* The Bell panel. Accelerators used: [acgo] bdsm */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling the terminal bell",
@@ -819,7 +826,11 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
                  "Action to happen when a &bell occurs:", IDC_BELLSTATIC,
                  "None (bell disabled)", IDC_BELL_DISABLED,
                  "Play Windows Default Sound", IDC_BELL_DEFAULT,
+                 "Play a custom sound file", IDC_BELL_WAVEFILE,
                  "Visual bell (flash window)", IDC_BELL_VISUAL, NULL);
+       editbutton(&cp, "Custom sound file to play as a bell:",
+                  IDC_BELL_WAVESTATIC, IDC_BELL_WAVEEDIT,
+                  "Bro&wse...", IDC_BELL_WAVEBROWSE);
         endbox(&cp);
        beginbox(&cp, "Control the bell overload behaviour",
                 IDC_BOX_BELL2);
@@ -1646,14 +1657,43 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
            break;
          case IDC_BELL_DISABLED:
          case IDC_BELL_DEFAULT:
+         case IDC_BELL_WAVEFILE:
          case IDC_BELL_VISUAL:
            if (HIWORD(wParam) == BN_CLICKED ||
                HIWORD(wParam) == BN_DOUBLECLICKED) {
-               if (LOWORD(wParam)==IDC_BELL_DISABLED) cfg.beep = 0;
-               if (LOWORD(wParam)==IDC_BELL_DEFAULT) cfg.beep = 1;
-               if (LOWORD(wParam)==IDC_BELL_VISUAL) cfg.beep = 2;
+               if (LOWORD(wParam)==IDC_BELL_DISABLED) cfg.beep = BELL_DISABLED;
+               if (LOWORD(wParam)==IDC_BELL_DEFAULT) cfg.beep = BELL_DEFAULT;
+               if (LOWORD(wParam)==IDC_BELL_WAVEFILE) cfg.beep = BELL_WAVEFILE;
+               if (LOWORD(wParam)==IDC_BELL_VISUAL) cfg.beep = BELL_VISUAL;
             }
            break;
+         case IDC_BELL_WAVEBROWSE:
+            memset(&of, 0, sizeof(of));
+#ifdef OPENFILENAME_SIZE_VERSION_400
+            of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+#else
+            of.lStructSize = sizeof(of);
+#endif
+            of.hwndOwner = hwnd;
+            of.lpstrFilter = "Wave Files\0*.WAV\0AllFiles\0*\0\0\0";
+            of.lpstrCustomFilter = NULL;
+            of.nFilterIndex = 1;
+            of.lpstrFile = filename; strcpy(filename, cfg.bell_wavefile);
+            of.nMaxFile = sizeof(filename);
+            of.lpstrFileTitle = NULL;
+            of.lpstrInitialDir = NULL;
+            of.lpstrTitle = "Select Bell Sound File";
+            of.Flags = 0;
+            if (GetOpenFileName(&of)) {
+                strcpy(cfg.bell_wavefile, filename);
+                SetDlgItemText (hwnd, IDC_BELL_WAVEEDIT, cfg.bell_wavefile);
+            }
+           break;
+         case IDC_BELL_WAVEEDIT:
+           if (HIWORD(wParam) == EN_CHANGE)
+               GetDlgItemText (hwnd, IDC_BELL_WAVEEDIT, cfg.bell_wavefile,
+                               sizeof(cfg.bell_wavefile)-1);
+           break;
          case IDC_BELLOVL:
            if (HIWORD(wParam) == BN_CLICKED ||
                HIWORD(wParam) == BN_DOUBLECLICKED)
index 8a9c6c7..84550eb 100644 (file)
--- a/window.c
+++ b/window.c
@@ -2637,6 +2637,15 @@ void fatalbox(char *fmt, ...) {
  * Beep.
  */
 void beep(int mode) {
-    if (mode == 1)
+    if (mode == BELL_DEFAULT) {
        MessageBeep(MB_OK);
+    } else if (mode == BELL_WAVEFILE) {
+       if (!PlaySound(cfg.bell_wavefile, NULL, SND_ASYNC | SND_FILENAME)) {
+           char buf[sizeof(cfg.bell_wavefile)+80];
+           sprintf(buf, "Unable to play sound file\n%s\n"
+                   "Using default sound instead", cfg.bell_wavefile);
+           MessageBox(hwnd, buf, "PuTTY Sound Error", MB_OK | MB_ICONEXCLAMATION);
+           cfg.beep = BELL_DEFAULT;
+       }
+    }
 }