📄 prefdialog.cpp
字号:
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
Portions Copyright (C) 1998-1999 EMusic.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: prefdialog.cpp,v 1.9 2000/06/22 15:27:18 elrod Exp $
____________________________________________________________________________*/
/* system headers */
#include <windows.h>
#include <windowsx.h>
#include <shlobj.h>
#include <commctrl.h>
#include <stdlib.h>
#include <assert.h>
/* project headers */
#include "config.h"
#include "prefdialog.h"
#include "preferences.h"
#include "log.h"
#include "registrar.h"
#include "resource.h"
typedef struct PrefsStruct {
Preferences* prefs;
// page 1
char defaultUI[256];
char defaultPMO[256];
int32 inputBufferSize;
int32 outputBufferSize;
int32 preBufferLength;
int32 decoderThreadPriority;
bool stayOnTop;
bool liveInTray;
// page 2
int32 streamInterval;
bool saveStreams;
char saveStreamsDirectory[MAX_PATH + 1];
bool useProxyServer;
char proxyServer[256]; // is there a domain name length limit???
bool useAlternateIP;
char alternateIP[16];
// page 3
bool enableLogging;
bool logMain;
bool logInput;
bool logOutput;
bool logDecoder;
bool logPerformance;
PrefsStruct()
{
memset(defaultUI, 0x00, sizeof(defaultUI));
memset(defaultPMO, 0x00, sizeof(defaultPMO));
memset(saveStreamsDirectory, 0x00, sizeof(saveStreamsDirectory));
memset(proxyServer, 0x00, sizeof(proxyServer));
memset(alternateIP, 0x00, sizeof(alternateIP));
}
}PrefsStruct;
static PrefsStruct originalValues;
static PrefsStruct currentValues;
static
void
GetPrefsValues(Preferences* prefs,
PrefsStruct* values)
{
uint32 size = 256;
prefs->GetPrefString(kPMOPref, values->defaultPMO, &size);
size = 256;
prefs->GetPrefString(kUIPref, values->defaultUI, &size);
prefs->GetPrefInt32(kDecoderThreadPriorityPref, &values->decoderThreadPriority);
prefs->GetPrefInt32(kInputBufferSizePref, &values->inputBufferSize);
prefs->GetPrefInt32(kOutputBufferSizePref, &values->outputBufferSize);
prefs->GetPrefInt32(kPreBufferPref, &values->preBufferLength);
prefs->GetPrefBoolean(kStayOnTopPref, &values->stayOnTop);
prefs->GetPrefBoolean(kLiveInTrayPref, &values->liveInTray);
prefs->GetPrefInt32(kStreamBufferIntervalPref, &values->streamInterval);
prefs->GetPrefBoolean(kSaveStreamsPref, &values->saveStreams);
size = 256;
prefs->GetPrefString(kProxyHostPref, values->proxyServer, &size);
prefs->GetPrefBoolean(kUseProxyPref, &values->useProxyServer);
size = MAX_PATH;
prefs->GetPrefString(kSaveStreamsDirPref, values->saveStreamsDirectory, &size);
size = 16;
prefs->GetPrefString(kAlternateNICAddressPref, values->alternateIP, &size);
prefs->GetPrefBoolean(kUseAlternateNICPref, &values->useAlternateIP);
prefs->GetPrefBoolean(kUseDebugLogPref, &values->enableLogging);
prefs->GetPrefBoolean(kLogMainPref, &values->logMain);
prefs->GetPrefBoolean(kLogDecodePref, &values->logDecoder);
prefs->GetPrefBoolean(kLogInputPref, &values->logInput);
prefs->GetPrefBoolean(kLogOutputPref, &values->logOutput);
prefs->GetPrefBoolean(kLogPerformancePref, &values->logPerformance);
}
static
void
SavePrefsValues(Preferences* prefs,
PrefsStruct* values)
{
prefs->SetPrefString(kPMOPref, values->defaultPMO);
prefs->SetPrefString(kUIPref, values->defaultUI);
prefs->SetPrefInt32(kDecoderThreadPriorityPref, values->decoderThreadPriority);
prefs->SetPrefInt32(kInputBufferSizePref, values->inputBufferSize);
prefs->SetPrefInt32(kOutputBufferSizePref, values->outputBufferSize);
prefs->SetPrefInt32(kPreBufferPref, values->preBufferLength);
prefs->SetPrefBoolean(kStayOnTopPref, values->stayOnTop);
prefs->SetPrefBoolean(kLiveInTrayPref, values->liveInTray);
prefs->SetPrefInt32(kStreamBufferIntervalPref, values->streamInterval);
prefs->SetPrefBoolean(kSaveStreamsPref, values->saveStreams);
prefs->SetPrefString(kSaveStreamsDirPref, values->saveStreamsDirectory);
prefs->SetPrefString(kProxyHostPref, values->proxyServer);
prefs->SetPrefBoolean(kUseProxyPref, values->useProxyServer);
prefs->SetPrefString(kAlternateNICAddressPref, values->alternateIP);
prefs->SetPrefBoolean(kUseAlternateNICPref, values->useAlternateIP);
prefs->SetPrefBoolean(kUseDebugLogPref, values->enableLogging);
prefs->SetPrefBoolean(kLogMainPref, values->logMain);
prefs->SetPrefBoolean(kLogDecodePref, values->logDecoder);
prefs->SetPrefBoolean(kLogInputPref, values->logInput);
prefs->SetPrefBoolean(kLogOutputPref, values->logOutput);
prefs->SetPrefBoolean(kLogPerformancePref, values->logPerformance);
}
static
BOOL
CALLBACK
PrefPage1Proc( HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
UINT result = 0;
static PROPSHEETPAGE* psp = NULL;
static Preferences* prefs = NULL;
static HWND hwndUI = NULL;
static HWND hwndPMO = NULL;
static HWND hwndPriority = NULL;
static HWND hwndInput = NULL;
static HWND hwndOutput = NULL;
static HWND hwndPrebuffer = NULL;
static HWND hwndStayOnTop = NULL;
static HWND hwndLiveInTray = NULL;
switch(msg)
{
case WM_INITDIALOG:
{
// remember these for later...
psp = (PROPSHEETPAGE*)lParam;
prefs = (Preferences*)psp->lParam;
// get the handles to all our controls
hwndUI = GetDlgItem(hwnd, IDC_UI);
hwndPMO = GetDlgItem(hwnd, IDC_PMO);
hwndPriority = GetDlgItem(hwnd, IDC_PRIORITY);
hwndInput = GetDlgItem(hwnd, IDC_INPUT);
hwndOutput = GetDlgItem(hwnd, IDC_OUTPUT);
hwndPrebuffer = GetDlgItem(hwnd, IDC_PREBUFFER);
hwndStayOnTop = GetDlgItem(hwnd, IDC_STAYONTOP);
hwndLiveInTray = GetDlgItem(hwnd, IDC_TRAY);
// get registries
Registrar registrar;
Registry pmo;
Registry ui;
registrar.SetSubDir("plugins");
registrar.SetSearchString("*.pmo");
registrar.InitializeRegistry(&pmo, prefs);
registrar.SetSearchString("*.ui");
registrar.InitializeRegistry(&ui, prefs);
// initialize our controls
int32 i = 0;
RegistryItem *item;
while(item = pmo.GetItem(i++))
{
ComboBox_AddString(hwndPMO, item->Name());
if(!strcmp(originalValues.defaultPMO, item->Name()))
{
ComboBox_SetCurSel(hwndPMO, i-1);
}
}
i = 0;
while(item = ui.GetItem(i++))
{
ComboBox_AddString(hwndUI, item->Name());
if(!strcmp(originalValues.defaultUI, item->Name()))
{
ComboBox_SetCurSel(hwndUI, i-1);
}
}
SendMessage(hwndPriority,
TBM_SETRANGE,
(WPARAM) TRUE,
(LPARAM) MAKELONG(0, 6));
SendMessage(hwndPriority,
TBM_SETPOS,
(WPARAM) TRUE,
(LPARAM) originalValues.decoderThreadPriority);
int32 value;
char temp[256];
value = originalValues.inputBufferSize;
sprintf(temp, "%d", value);
Edit_LimitText(hwndInput, 4);
Edit_SetText(hwndInput, temp);
value = originalValues.outputBufferSize;
sprintf(temp, "%d", value);
Edit_LimitText(hwndOutput, 4);
Edit_SetText(hwndOutput, temp);
value = originalValues.preBufferLength;
sprintf(temp, "%d", value);
Edit_LimitText(hwndPrebuffer, 2);
Edit_SetText(hwndPrebuffer, temp);
Button_SetCheck(hwndStayOnTop, originalValues.stayOnTop);
Button_SetCheck(hwndLiveInTray, originalValues.liveInTray);
break;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_PMO:
{
if(HIWORD(wParam) == CBN_CLOSEUP)
{
memset(currentValues.defaultPMO, 0x00, 256);
ComboBox_GetText( hwndPMO,
currentValues.defaultPMO,
256);
if(memcmp( &originalValues,
¤tValues,
sizeof(PrefsStruct)))
{
PropSheet_Changed(GetParent(hwnd), hwnd);
}
else
{
PropSheet_UnChanged(GetParent(hwnd), hwnd);
}
}
break;
}
case IDC_UI:
{
if(HIWORD(wParam) == CBN_CLOSEUP)
{
memset(currentValues.defaultUI, 0x00, 256);
ComboBox_GetText( hwndUI,
currentValues.defaultUI,
256);
if(memcmp( &originalValues,
¤tValues,
sizeof(PrefsStruct)))
{
PropSheet_Changed(GetParent(hwnd), hwnd);
}
else
{
PropSheet_UnChanged(GetParent(hwnd), hwnd);
}
}
break;
}
case IDC_INPUT:
{
if(HIWORD(wParam) == EN_CHANGE)
{
char text[128];
Edit_GetText(hwndInput, text, sizeof(text));
currentValues.inputBufferSize = atoi(text);
if(memcmp( &originalValues,
¤tValues,
sizeof(PrefsStruct)))
{
PropSheet_Changed(GetParent(hwnd), hwnd);
}
else
{
PropSheet_UnChanged(GetParent(hwnd), hwnd);
}
}
break;
}
case IDC_OUTPUT:
{
if(HIWORD(wParam) == EN_CHANGE)
{
char text[128];
Edit_GetText(hwndOutput, text, sizeof(text));
currentValues.outputBufferSize = atoi(text);
if(memcmp( &originalValues,
¤tValues,
sizeof(PrefsStruct)))
{
PropSheet_Changed(GetParent(hwnd), hwnd);
}
else
{
PropSheet_UnChanged(GetParent(hwnd), hwnd);
}
}
break;
}
case IDC_PREBUFFER:
{
if(HIWORD(wParam) == EN_CHANGE)
{
char text[128];
Edit_GetText(hwndPrebuffer, text, sizeof(text));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -