📄 freeamptheme.cpp
字号:
m_pWindow->ControlStringValue("Logo", false, oUrl);
if (oUrl.length() == 0)
oUrl = BRANDING_URL;
#ifdef WIN32
Int32PropValue *pProp;
HWND hWnd;
if (IsError(m_pContext->props->GetProperty("MainWindow",
(PropValue **)&pProp)))
hWnd = NULL;
else
hWnd = (HWND)pProp->GetInt32();
ShellExecute(hWnd, "open", oUrl.c_str(),
NULL, NULL, SW_SHOWNORMAL);
#else
LaunchBrowser((char *)oUrl.c_str());
#endif
return kError_NoErr;
}
if (oControlName == string("HeadlineInfo") && eMesg == CM_Pressed)
{
if (m_oHeadlineUrl.length() == 0)
return kError_NoErr;
#ifdef WIN32
Int32PropValue *pProp;
HWND hWnd;
if (IsError(m_pContext->props->GetProperty("MainWindow",
(PropValue **)&pProp)))
hWnd = NULL;
else
hWnd = (HWND)pProp->GetInt32();
ShellExecute(hWnd, "open", m_oHeadlineUrl.c_str(),
NULL, NULL, SW_SHOWNORMAL);
#else
LaunchBrowser((char *)m_oHeadlineUrl.c_str());
#endif
return kError_NoErr;
}
if (oControlName == string("HeadlineStreamInfo") && eMesg == CM_Pressed)
{
bool bPlay;
if (m_oHeadlineUrl.length() == 0)
return kError_NoErr;
m_pContext->prefs->GetPrefBoolean(kPlayImmediatelyPref, &bPlay);
if (bPlay)
{
m_pContext->target->AcceptEvent(new Event(CMD_Stop));
m_pContext->plm->RemoveAll();
m_pContext->plm->AddItem(m_oHeadlineUrl);
m_pContext->target->AcceptEvent(new Event(CMD_Play));
}
else
m_pContext->plm->AddItem(m_oHeadlineUrl);
return kError_NoErr;
}
if (oControlName == string("Help") && eMesg == CM_Pressed)
{
ShowHelp();
return kError_NoErr;
}
if (oControlName == string("Credits") && eMesg == CM_Pressed)
{
ShowThemeCredits();
return kError_NoErr;
}
if (strncmp(oControlName.c_str(), "Eq", 2) == 0 && eMesg == CM_ValueChanged)
{
int iValue;
m_pWindow->ControlIntValue(oControlName, false, iValue);
m_eq->ChangeValue(atoi(oControlName.c_str() + 2), iValue);
return kError_NoErr;
}
if (oControlName == string("Preamp") && eMesg == CM_ValueChanged)
{
int iValue;
m_pWindow->ControlIntValue(oControlName, false, iValue);
m_eq->ChangePreamp(iValue);
return kError_NoErr;
}
if (oControlName == string("EqEnable") && eMesg == CM_Pressed)
{
int iState;
m_pWindow->ControlIntValue(oControlName, false, iState);
if (iState == 1)
{
m_eq->Enable(true);
iState = 0;
}
else
{
m_eq->Enable(false);
iState = 1;
}
m_pWindow->ControlIntValue(oControlName, true, iState);
return kError_NoErr;
}
if (oControlName == string("Title") && eMesg == CM_MouseDoubleClick)
{
m_pContext->target->AcceptEvent(new
Event(CMD_EditCurrentPlaylistItemInfo));
return kError_NoErr;
}
if (oControlName == string("SigIndicator") && eMesg == CM_Pressed)
{
if (!m_pContext->aps->IsTurnedOn())
return kError_NoErr;
if (m_sigState == kSigsPending)
m_pContext->catalog->StartGeneratingSigs();
else
if (m_sigState == kGeneratingSigs)
m_pContext->catalog->StopGeneratingSigs();
}
return kError_NoErr;
}
void FreeAmpTheme::InitControls(void)
{
bool bSet, bEnable;
int iState;
string oWelcome(szWelcomeMsg);
assert(m_pWindow);
// Set the volume control
if (m_iVolume >= 0)
{
bSet = true;
m_pWindow->ControlIntValue(string("Volume"), true, m_iVolume);
m_pWindow->ControlIntValue(string("Balance"), true, m_iBalance);
}
else
{
int iTemp = 50;
m_pWindow->ControlIntValue(string("Balance"), true, iTemp);
bSet = false;
}
m_pWindow->ControlEnable(string("Volume"), true, bSet);
m_pWindow->ControlEnable(string("Balance"), true, bSet);
// Set the seek control
bSet = (m_iTotalSeconds < 0) ? false : true;
if (bSet)
m_pWindow->ControlIntValue(string("Seek"), true, m_iSeekPos);
m_pWindow->ControlEnable(string("Seek"), true, bSet);
// Set the Play/Pause buttons
iState = m_bPlayShown ? 0 : 1;
m_pWindow->ControlIntValue(string("PlayPause"), true, iState);
m_pWindow->ControlIntValue(string("PlayStop"), true, iState);
iState = m_bPaused ? 1 : 0;
m_pWindow->ControlIntValue(string("MPause"), true, iState);
bEnable = m_bPlayShown;
m_pWindow->ControlEnable(string("Play"), true, bEnable);
bEnable = !m_bPlayShown;
m_pWindow->ControlEnable(string("Pause"), true, bEnable);
m_pWindow->ControlEnable(string("Stop"), true, bEnable);
// Set the title text field to the current meta data, or if no
// is available, show the welcome message
if (m_oTitle.length() == 0)
m_pWindow->ControlStringValue(string("Title"), true, oWelcome);
else
m_pWindow->ControlStringValue(string("Title"), true, m_oTitle);
// Ask the playlist manager what the current repeat mode is
// and set the controls appropriately.
switch (m_pContext->plm->GetRepeatMode())
{
case kPlaylistMode_RepeatNone:
iState = 0;
break;
case kPlaylistMode_RepeatOne:
iState = 1;
break;
case kPlaylistMode_RepeatAll:
iState = 2;
break;
default:
break;
}
m_pWindow->ControlIntValue(string("Repeat"), true, iState);
iState = m_pContext->plm->GetShuffleMode() ? 1 : 0;
m_pWindow->ControlIntValue(string("Shuffle"), true, iState);
m_pWindow->ControlStringValue("StreamInfo", true, m_oStreamInfo);
if ((m_pWindow->DoesControlExist("HeadlineInfo") ||
m_pWindow->DoesControlExist("HeadlineStreamInfo")) && m_pHeadlines)
{
if (m_pHeadlineGrabber)
{
m_pHeadlineGrabber->SetInfo(*m_pHeadlines);
m_pHeadlineGrabber->Resume();
}
else
{
m_pHeadlineGrabber = new Headlines(m_pContext);
m_pHeadlineGrabber->SetInfo(*m_pHeadlines);
}
}
else
{
if (m_pHeadlineGrabber)
m_pHeadlineGrabber->Pause();
}
bEnable = false;
m_pWindow->ControlEnable(string("StereoIndicator"), true, bEnable);
m_pWindow->ControlEnable(string("MonoIndicator"), true, bEnable);
m_pWindow->ControlEnable(string("PlayIndicator"), true, bEnable);
m_pWindow->ControlEnable(string("PauseIndicator"), true, bEnable);
bEnable = true;
m_pWindow->ControlEnable(string("StopIndicator"), true, bEnable);
iState = m_eq->IsEnabled() == false;
m_pWindow->ControlIntValue(string("EqEnable"), true, iState);
iState = m_iMuteVolume != -1;
m_pWindow->ControlIntValue(string("Mute"), true, iState);
if (m_sigState == kIdle || !m_pContext->aps->IsTurnedOn())
iState = 0;
else
if (m_sigState == kGeneratingSigs)
iState = 2;
else
iState = 1;
m_pWindow->ControlIntValue(string("SigIndicator"), true, iState);
m_eq->InitControls(m_pWindow);
}
// This function gets called after the window object is created,
// but before the window itself gets created
void FreeAmpTheme::InitWindow(void)
{
bool bValue;
m_pContext->prefs->GetPrefBoolean(kStayOnTopPref, &bValue);
m_pWindow->SetStayOnTop(bValue);
m_pContext->prefs->GetPrefBoolean(kLiveInTrayPref, &bValue);
m_pWindow->SetLiveInToolbar(bValue);
}
void FreeAmpTheme::ReloadTheme(void)
{
char *szTemp;
uint32 iLen = _MAX_PATH;
string oThemePath(""), oThemeFile("theme.xml");
Error eRet;
struct _stat buf;
szTemp = new char[iLen];
m_pContext->prefs->GetPrefString(kThemePathPref, szTemp, &iLen);
if (_stat(szTemp, &buf) < 0 && strlen(szTemp) < 1)
{
// If the theme doesn't exist, let's try to prepend the install/theme dir
char *dir;
uint32 len = _MAX_PATH;
dir = new char[_MAX_PATH];
m_pContext->prefs->GetPrefString(kInstallDirPref, dir, &len);
oThemePath = string(dir);
#if defined(unix)
oThemePath += string(BRANDING_SHARE_PATH);
#endif
oThemePath += string(DIR_MARKER_STR);
oThemePath += string("themes");
oThemePath += string(DIR_MARKER_STR);
delete [] dir;
}
oThemePath += szTemp;
iLen = 255;
m_pContext->prefs->GetPrefString(kThemeDefaultFontPref, szTemp, &iLen);
SetDefaultFont(string(szTemp));
eRet = LoadTheme(oThemePath, m_oCurrentWindow);
if (IsError(eRet))
{
MessageDialog oBox(m_pContext);
string oErr, oMessage(szParseError);
GetErrorString(oErr);
oMessage += oErr;
oBox.Show(oMessage.c_str(), string(BRANDING), kMessageOk);
}
delete [] szTemp;
}
void FreeAmpTheme::SetVolume(int iVolume, int iBalance)
{
string oVol("Volume: ");
char szPercent[40];
int iLeft, iRight, iLastBal = m_iBalance;
if (iBalance < 50) // more focus on left channel
{
iLeft = iVolume;
iRight = iVolume - (iVolume * (50 - iBalance) * 2 / 100);
}
else
{
iLeft = iVolume - (iVolume * (iBalance - 50) * 2 / 100);
iRight = iVolume;
}
if (m_iMuteVolume != -1 && iVolume != 0)
{
int iState = 0;
m_iMuteVolume = -1;
m_pWindow->ControlIntValue(string("Mute"), true, iState);
}
m_iVolume = iVolume;
m_iBalance = iBalance;
m_pContext->target->AcceptEvent(new
VolumeEvent(CMD_SetVolume, iLeft, iRight));
m_pWindow->ControlIntValue(string("Volume"), true, m_iVolume);
m_pWindow->ControlIntValue(string("Balance"), true, m_iBalance);
if (m_iBalance == iLastBal)
{
sprintf(szPercent, "%d%%", iVolume);
oVol += string(szPercent);
m_pWindow->ControlStringValue(string("Info"), true, oVol);
oVol = string(szPercent);
m_pWindow->ControlStringValue(string("VolumeText"), true, oVol);
}
else
{
if (m_iBalance == 50)
strcpy(szPercent, "Equal balance");
else
if (m_iBalance < 50)
sprintf(szPercent, "%d%% Left", 100 - m_iBalance * 2);
else
sprintf(szPercent, "%d%% Right", (m_iBalance - 50) * 2);
oVol = string("Balance: ") + string(szPercent);
m_pWindow->ControlStringValue(string("Info"), true, oVol);
}
}
void FreeAmpTheme::HandleKeystroke(unsigned char cKey)
{
switch(cKey)
{
case 'p':
case 'P':
m_pContext->target->AcceptEvent(new Event(CMD_Play));
break;
case 'S':
case 's':
m_pContext->target->AcceptEvent(new Event(CMD_Stop));
break;
case 'u':
case 'U':
m_pContext->target->AcceptEvent(new Event(CMD_Pause));
break;
case 'M':
case 'm':
m_pContext->target->AcceptEvent(new Event(CMD_ToggleMusicBrowserUI));
break;
case 'n':
case 'N':
m_pContext->target->AcceptEvent(new Event(CMD_NextMediaPiece));
break;
case 'r':
case 'R':
m_pContext->target->AcceptEvent(new Event(CMD_PrevMediaPiece));
break;
case 'd':
case 'D':
m_pContext->target->AcceptEvent(new Event(CMD_ToggleDownloadUI));
break;
case 'o':
case 'O':
m_pContext->target->AcceptEvent(new ShowPreferencesEvent(0));
break;
case 'c':
case 'C':
ShowThemeCredits();
break;
case 't':
case 'T':
ReloadTheme();
break;
case 'i':
case 'I':
{
string oText;
m_eTitleDisplayState =
(m_eTitleDisplayState == kName) ? kNameArtist :
(m_eTitleDisplayState == kNameArtist) ? kNameArtistAlbum : kName;
switch(m_eTitleDisplayState)
{
case kName:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -