? audio.c
? changes
? patchgen
? winecfg.patch
Index: En.rc
===================================================================
RCS file: /home/wine/wine/programs/winecfg/En.rc,v
retrieving revision 1.15
diff -u -r1.15 En.rc
--- En.rc	7 Jan 2004 00:43:40 -0000	1.15
+++ En.rc	17 Jan 2004 03:10:44 -0000
@@ -89,7 +89,6 @@
 		    
     EDITTEXT        IDC_DESKTOP_WIDTH,64,115,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED
     EDITTEXT        IDC_DESKTOP_HEIGHT,117,115,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED
-		    
 END
 
 IDD_DLLCFG DIALOG DISCARDABLE  0, 0, 260, 250
@@ -173,10 +172,18 @@
     CONTROL         "Manually Assign:",IDC_RADIO_ASSIGN,"Button",
                     BS_AUTORADIOBUTTON,21,104,69,10
     GROUPBOX        "Label and Serial Number",IDC_BOX_LABELSERIAL,6,68,189,79
+END
 
+IDD_AUDIOCFG DIALOG DISCARDABLE  0, 0, 260, 250
+STYLE WS_CHILD | WS_DISABLED
+FONT 8, "MS Sans Serif"
+BEGIN
+    LTEXT	"Audio driver: ",IDC_STATIC,10,20,60,8
+    COMBOBOX	IDC_AUDIO_DRIVER,70,18,85,85,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    PUSHBUTTON	"Autodetect",IDC_AUDIO_AUTODETECT,170,15,45,18
 END
 
-STRINGTABLE DISCARDABLE 
+STRINGTABLE DISCARDABLE
 BEGIN
     IDS_WINE_VERSION        "CVS"
     IDS_TAB_GENERAL         "General"
Index: Makefile.in
===================================================================
RCS file: /home/wine/wine/programs/winecfg/Makefile.in,v
retrieving revision 1.7
diff -u -r1.7 Makefile.in
--- Makefile.in	7 Jan 2004 00:43:40 -0000	1.7
+++ Makefile.in	17 Jan 2004 03:10:44 -0000
@@ -8,6 +8,7 @@
 
 C_SRCS = \
 	appdefaults.c \
+	audio.c \
 	drive.c \
 	libraries.c \
 	main.c \
Index: drive.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/drive.c,v
retrieving revision 1.10
diff -u -r1.10 drive.c
--- drive.c	27 Nov 2003 00:59:36 -0000	1.10
+++ drive.c	17 Jan 2004 03:10:45 -0000
@@ -525,7 +525,7 @@
 INT_PTR CALLBACK DriveEditDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
   int selection;
-  
+
   switch (uMsg)  {
       case WM_INITDIALOG: {
 	editWindowLetter = (char) lParam;
@@ -642,7 +642,10 @@
       case WM_COMMAND:
 	switch (LOWORD(wParam)) {
 	    case IDC_LIST_DRIVES:
-	      if (HIWORD(wParam) == LBN_DBLCLK) selection = -1;
+	      /* double click should open the edit window for the chosen drive */
+	      if (HIWORD(wParam) == LBN_DBLCLK)
+	        SendMessageA(hDlg, WM_COMMAND, IDC_BUTTON_EDIT, 0);
+
 	      if (HIWORD(wParam) == LBN_SELCHANGE) lastSel = SendDlgItemMessage(hDlg, IDC_LIST_DRIVES, LB_GETCURSEL, 0, 0);
 	      break;
 
@@ -684,7 +687,6 @@
 	      break;
 	}
 	break;
-
   }
 
   return FALSE;
Index: main.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/main.c,v
retrieving revision 1.12
diff -u -r1.12 main.c
--- main.c	7 Jan 2004 00:43:40 -0000	1.12
+++ main.c	17 Jan 2004 03:10:46 -0000
@@ -177,7 +177,8 @@
     return FALSE;
 }
 
-#define NUM_PROPERTY_PAGES 5
+#define NUM_PROPERTY_PAGES 6
+
 INT_PTR
 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
 {
@@ -244,6 +245,15 @@
     psp[4].pfnDlgProc = DriveDlgProc;
     psp[4].pszTitle = "Drives";
     psp[4].lParam = 0;
+
+    psp[5].dwSize = sizeof (PROPSHEETPAGE);
+    psp[5].dwFlags = PSP_USETITLE;
+    psp[5].hInstance = hInstance;
+    psp[5].u.pszTemplate = MAKEINTRESOURCE (IDD_AUDIOCFG);
+    psp[5].u2.pszIcon = NULL;
+    psp[5].pfnDlgProc = AudioDlgProc;
+    psp[5].pszTitle = "Audio";
+    psp[5].lParam = 0;
     
     /*
      * Fill out the PROPSHEETHEADER
Index: properties.c
===================================================================
RCS file: /home/wine/wine/programs/winecfg/properties.c,v
retrieving revision 1.5
diff -u -r1.5 properties.c
--- properties.c	16 Sep 2003 01:08:02 -0000	1.5
+++ properties.c	17 Jan 2004 03:10:46 -0000
@@ -77,6 +77,18 @@
     {"", -1}
 };
 
+static AUDIO_DRIVER sAudioDrivers[] = {
+  {"Alsa", "winealsa.drv"},
+  {"aRts", "winearts.drv"},
+  {"OSS", "wineoss.drv"},
+  {"Jack", "winejack.drv"},
+  {"Nas", "winenas.drv"},
+  {"Audio IO(Solaris)", "wineaudioio.drv"},
+  {"Disable sound", ""},
+  {"", ""}
+};
+ 
+
 
 /*****************************************************************************
  */
@@ -107,4 +119,11 @@
 DLL_DESC* getDLLDefaults(void)
 {
     return sDLLType;
+}
+
+/*****************************************************************************
+ */
+AUDIO_DRIVER* getAudioDrivers(void)
+{
+    return sAudioDrivers;
 }
Index: properties.h
===================================================================
RCS file: /home/wine/wine/programs/winecfg/properties.h,v
retrieving revision 1.8
diff -u -r1.8 properties.h
--- properties.h	8 Sep 2003 19:29:28 -0000	1.8
+++ properties.h	17 Jan 2004 03:10:46 -0000
@@ -60,6 +60,11 @@
     HDPA  DLLs;
 } APP_DESC;
 
+typedef struct
+{
+  char szName[MAX_NAME_LENGTH];
+  char szDriver[MAX_NAME_LENGTH];
+} AUDIO_DRIVER;
 
 typedef struct
 {
@@ -86,5 +91,6 @@
 VERSION_DESC *getDOSVersions(void);
 VERSION_DESC *getWinelook(void);
 DLL_DESC *getDLLDefaults(void);
+AUDIO_DRIVER *getAudioDrivers(void);
 
 #endif
Index: resource.h
===================================================================
RCS file: /home/wine/wine/programs/winecfg/resource.h,v
retrieving revision 1.10
diff -u -r1.10 resource.h
--- resource.h	7 Jan 2004 00:43:40 -0000	1.10
+++ resource.h	17 Jan 2004 03:10:46 -0000
@@ -30,10 +30,11 @@
 #define IDB_WINE                        104
 #define IDD_GENERALCFG                  107
 #define IDD_APPCFG                      108
-#define IDD_X11DRVCFG                   109
-#define IDD_DLLCFG                      110
-#define IDD_DRIVECFG                    111
-#define IDD_SYSTEMCFG                   112
+#define IDD_AUDIOCFG                    109
+#define IDD_X11DRVCFG                   110
+#define IDD_DLLCFG                      111
+#define IDD_DRIVECFG                    112
+#define IDD_SYSTEMCFG                   113
 #define IDD_DRIVE_EDIT                  114
 #define IDB_WINE_LOGO                   200
 #define IDC_TABABOUT                    1001
@@ -120,3 +121,7 @@
 #define IDC_EDITING_APP                 1082
 #define IDC_ADD_APPDEFAULT              1083
 #define IDC_REMOVE_APPDEFAULT           1084
+
+/* audio tab */
+#define IDC_AUDIO_AUTODETECT            1085
+#define IDC_AUDIO_DRIVER                1086
Index: winecfg.h
===================================================================
RCS file: /home/wine/wine/programs/winecfg/winecfg.h,v
retrieving revision 1.12
diff -u -r1.12 winecfg.h
--- winecfg.h	7 Jan 2004 00:43:40 -0000	1.12
+++ winecfg.h	17 Jan 2004 03:10:47 -0000
@@ -111,6 +111,9 @@
 INT_PTR CALLBACK AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK LibrariesDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
+/* Audio config dialog */
+INT_PTR CALLBACK AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
 /* some basic utilities to make win32 suck less */
 char *getDialogItemText(HWND hDlg, WORD controlID);
 #define disable(id) EnableWindow(GetDlgItem(dialog, id), 0);
--- /dev/null	2003-12-09 22:40:48.000000000 -0500
+++ audio.c	2004-01-16 14:43:54.000000000 -0500
@@ -0,0 +1,198 @@
+/*
+ * Audio management UI code
+ *
+ * Copyright 2004 Chris Morgan
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <windef.h>
+#include <winbase.h>
+#include <winreg.h>
+#include <wine/debug.h>
+#include <shellapi.h>
+#include <objbase.h>
+#include <shlguid.h>
+#include <shlwapi.h>
+#include <shlobj.h>
+
+#include "winecfg.h"
+#include "resource.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
+
+/* Select the correct entry in the combobox based on drivername */
+void selectAudioDriver(HWND hDlg, char *drivername)
+{
+  int i;
+  const AUDIO_DRIVER *pAudioDrv = NULL;
+
+  if ((pAudioDrv = getAudioDrivers()))
+  {
+    for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++)
+    {
+      if (!strcmp (pAudioDrv->szDriver, drivername))
+      {
+	addTransaction("Winmm", "Drivers", ACTION_SET, pAudioDrv->szDriver);
+	SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_SETCURSEL,
+			   (WPARAM) i, 0);
+      }
+    }
+  }
+}
+
+void
+initAudioDlg (HWND hDlg)
+{
+  char *curAudioDriver = getConfigValue("Winmm", "Drivers", "winealsa.drv");
+  const AUDIO_DRIVER *pAudioDrv = NULL;
+  int i;
+
+    if ((pAudioDrv = getAudioDrivers ()))
+    {
+	for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++)
+	{
+	    SendDlgItemMessage (hDlg, IDC_AUDIO_DRIVER, CB_ADDSTRING,
+				0, (LPARAM) pAudioDrv->szName);
+	    if (!strcmp (pAudioDrv->szDriver, curAudioDriver))
+	      selectAudioDriver(hDlg, (char*)pAudioDrv->szDriver);
+	}
+    }
+}
+
+char *audioAutoDetect(void)
+{
+  struct stat buf;
+  const char *argv_new[4];
+  int fd;
+
+  char *driversFound[10];
+  char *name[10];
+  int numFound = 0;
+
+  argv_new[0] = "/bin/sh";
+  argv_new[1] = "-c";
+  argv_new[3] = NULL;
+
+  /* try to detect arts */
+  argv_new[2] = "ps awx|grep artsd|grep -v grep|grep artsd > /dev/null";
+  if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
+  {
+    driversFound[numFound] = "winearts.drv";
+    name[numFound] = "aRts";
+    numFound++;
+  }
+
+  /* try to detect jack */
+  argv_new[2] = "ps awx|grep jackd|grep -v grep|grep jackd > /dev/null";
+  if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
+  {
+    driversFound[numFound] = "winejack.drv";
+    name[numFound] = "jack";
+    numFound++;
+  }
+
+  /* try to detect nas */
+  /* TODO */
+
+  /* try to detect audioIO (solaris) */
+  /* TODO */
+
+  /* try to detect alsa */
+  if(!stat("/proc/asound", &buf))
+  {
+    driversFound[numFound] = "winealsa.drv";
+    name[numFound] = "Alsa";
+    numFound++;
+  }
+
+  /* try to detect oss */
+  fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK);
+  if(fd)
+  {
+    close(fd);
+    driversFound[numFound] = "wineoss.drv";
+    name[numFound] = "OSS";
+    numFound++;
+  }
+
+
+  if(numFound == 0)
+  {
+    MessageBox(NULL, "Could not detect any audio devices/servers", "Failed", MB_OK);
+    return "";
+  }
+  else
+  {
+    /* TODO: possibly smarter handling of multiple drivers? */
+    char text[128];
+    snprintf(text, sizeof(text), "Found %s", name[0]);
+    MessageBox(NULL, (LPCTSTR)text, "Successful", MB_OK);
+    return driversFound[0];
+  }
+}
+
+
+INT_PTR CALLBACK
+AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+  switch (uMsg) {
+      case WM_COMMAND:
+	switch (LOWORD(wParam)) {
+	   case IDC_AUDIO_AUTODETECT:
+	      selectAudioDriver(hDlg, audioAutoDetect());
+	      break;
+	   case IDC_AUDIO_DRIVER:
+	     if ((HIWORD(wParam) == CBN_SELCHANGE) ||
+		 (HIWORD(wParam) == CBN_SELCHANGE))
+	     {
+		const AUDIO_DRIVER *pAudioDrv = getAudioDrivers();
+		int selected_driver = SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
+		selectAudioDriver(hDlg, (char*)pAudioDrv[selected_driver].szDriver);
+	     }
+	     break;
+	}
+	break;
+	
+      case WM_NOTIFY:
+	switch(((LPNMHDR)lParam)->code) {
+	    case PSN_KILLACTIVE:
+	      SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
+	      break;
+	    case PSN_APPLY:
+	      SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
+	      break;
+	    case PSN_SETACTIVE:
+	      break;
+	}
+	break;
+
+  case WM_INITDIALOG:
+    initAudioDlg(hDlg);
+    break;
+  }
+
+  return FALSE;
+}
