📄 freeamptheme.cpp
字号:
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);
}
// 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->GetStayOnTop(&bValue);
m_pWindow->SetStayOnTop(bValue);
m_pContext->prefs->GetLiveInTray(&bValue);
m_pWindow->SetLiveInToolbar(bValue);
}
void FreeAmpTheme::ReloadTheme(void)
{
char szTemp[255];
uint32 iLen = 255;
string oThemePath, oThemeFile("theme.xml");
Error eRet;
m_pContext->prefs->GetPrefString(kThemePathPref, szTemp, &iLen);
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);
}
}
void FreeAmpTheme::SetVolume(int iVolume)
{
string oVol("Volume: ");
char szPercent[10];
m_iVolume = iVolume;
m_pContext->target->AcceptEvent(new
VolumeEvent(CMD_SetVolume, m_iVolume));
m_pWindow->ControlIntValue(string("Volume"), true, m_iVolume);
sprintf(szPercent, "%d%%", iVolume);
oVol += 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 'h':
case 'H':
ShowHelp();
break;
}
}
bool FreeAmpTheme::HandleMenuCommand(uint32 uCommand)
{
switch(uCommand)
{
case kMCMyMusic:
m_pContext->target->AcceptEvent(
new Event(CMD_ToggleMusicBrowserUI));
return true;
case kMCPlay:
m_pContext->target->AcceptEvent(
new Event(CMD_Play));
return true;
case kMCStop:
m_pContext->target->AcceptEvent(
new Event(CMD_Stop));
return true;
case kMCPause:
m_pContext->target->AcceptEvent(
new Event(CMD_Pause));
return true;
case kMCNext:
m_pContext->target->AcceptEvent(
new Event(CMD_NextMediaPiece));
return true;
case kMCPrev:
m_pContext->target->AcceptEvent(
new Event(CMD_PrevMediaPiece));
return true;
case kMCExit:
m_pContext->target->AcceptEvent(
new Event(CMD_QuitPlayer));
return true;
}
return false;
}
void FreeAmpTheme::UpdateTimeDisplay(int iCurrentSeconds)
{
string oText;
char szText[20];
int iSeconds;
if (m_eTimeDisplayState == kTimeRemaining && m_iTotalSeconds >= 0)
{
iSeconds = m_iTotalSeconds - iCurrentSeconds - 1;
if (iSeconds > 3600)
sprintf(szText, "-%d:%02d:%02d",
iSeconds / 3600,
(iSeconds % 3600) / 60,
iSeconds % 60);
else
sprintf(szText, "-%d:%02d",
(iSeconds % 3600) / 60,
iSeconds % 60);
}
else
if (iCurrentSeconds >= 0)
{
if (iCurrentSeconds > 3600)
sprintf(szText, "%d:%02d:%02d",
iCurrentSeconds / 3600,
(iCurrentSeconds % 3600) / 60,
iCurrentSeconds % 60);
else
sprintf(szText, "%d:%02d",
(iCurrentSeconds % 3600) / 60,
iCurrentSeconds % 60);
}
else
sprintf(szText, "0:00");
oText = string(szText);
if (m_eTimeDisplayState == kTimeRemaining &&
m_pWindow->DoesControlExist("TimeRemaining") &&
m_iTotalSeconds >= 0)
m_pWindow->ControlStringValue("TimeRemaining", true, oText);
else
m_pWindow->ControlStringValue("Time", true, oText);
}
void FreeAmpTheme::UpdateMetaData(const PlaylistItem *pItem)
{
if (pItem->GetMetaData().Title().length() > 0 ||
pItem->GetMetaData().Artist().length() > 0)
{
string oText;
m_oTitle = pItem->GetMetaData().Title();
if (pItem->GetMetaData().Artist().length() > 0)
m_oTitle += string(" - ") + pItem->GetMetaData().Artist();
oText = string(BRANDING": ") + m_oTitle;
m_pWindow->SetTitle(oText);
}
else
m_oTitle = "";
m_pWindow->ControlStringValue(string("Title"), true, m_oTitle);
}
void FreeAmpTheme::DropFiles(vector<string> *pFileList)
{
char ext[_MAX_PATH];
char url[_MAX_PATH + 7];
uint32 length, countbefore;
vector<string>::iterator i;
countbefore = m_pContext->plm->CountItems();
for(i = pFileList->begin(); i != pFileList->end(); i++)
{
char *pExtension = NULL;
vector<char*> fileList;
struct _stat st;
_stat((*i).c_str(), &st);
if(st.st_mode & _S_IFDIR)
{
HANDLE findFileHandle = NULL;
WIN32_FIND_DATA findData;
char findPath[_MAX_PATH + 1];
char* file;
vector<PlaylistItem*> oList;
strcpy(findPath, (*i).c_str());
strcat(findPath, DIR_MARKER_STR);
strcat(findPath, "*.*");
file = strrchr(findPath, DIR_MARKER) + 1;
findFileHandle = FindFirstFile(findPath, &findData);
if(findFileHandle != INVALID_HANDLE_VALUE)
{
do
{
pExtension = strrchr(findData.cFileName, '.');
if (!pExtension)
continue;
strcpy(ext, pExtension + 1);
ToUpper(ext);
if (m_pContext->player->IsSupportedExtension(ext))
{
strcpy(findPath, (*i).c_str());
strcat(findPath, DIR_MARKER_STR);
strcat(findPath, findData.cFileName);
length = sizeof(url);
FilePathToURL(findPath, url, &length);
PlaylistItem* item = new PlaylistItem(url);
oList.push_back(item);
}
}while(FindNextFile(findFileHandle, &findData));
FindClose(findFileHandle);
}
if (oList.size() > 0)
m_pContext->plm->AddItems(&oList);
}
else
{
PlaylistFormatInfo oInfo;
char ext[_MAX_PATH];
int j;
Error eRet = kError_NoErr;
pExtension = strrchr((*i).c_str(), '.');
if (!pExtension)
continue;
strcpy(ext, pExtension + 1);
ToUpper(ext);
for(j = 0; ; j++)
{
eRet = m_pContext->plm->GetSupportedPlaylistFormats(&oInfo, j);
if (IsError(eRet))
break;
if (strcasecmp(oInfo.GetExtension(), ext) == 0)
break;
}
if (!IsError(eRet))
{
length = sizeof(url);
FilePathToURL((*i).c_str(), url, &length);
m_pContext->plm->ReadPlaylist(url);
}
else
if (m_pContext->player->IsSupportedExtension(ext))
{
length = sizeof(url);
FilePathToURL((*i).c_str(), url, &length);
m_pContext->plm->AddItem(url);
}
}
}
if (countbefore == 0)
m_pContext->target->AcceptEvent(new Event(CMD_Play));
}
void FreeAmpTheme::PostWindowCreate(void)
{
#ifdef WIN32
Int32PropValue *pProp;
pProp = new Int32PropValue((int)((Win32Window *)m_pWindow)->GetWindowHandle());
m_pContext->props->SetProperty("MainWindow", pProp);
#endif
string winTitle = string(BRANDING);
m_pWindow->SetTitle(winTitle);
}
void FreeAmpTheme::ShowHelp(void)
{
string oHelpFile;
char dir[_MAX_PATH];
uint32 len = sizeof(dir);
m_pContext->prefs->GetInstallDirectory(dir, &len);
oHelpFile = string(dir);
oHelpFile += string(DIR_MARKER_STR);
#ifdef unix
oHelpFile += string("../share/");
#endif
oHelpFile += string(HELP_FILE);
#ifdef WIN32
Int32PropValue *pProp;
HWND hWnd;
if (IsError(m_pContext->props->GetProperty("MainWindow",
(PropValue **)&pProp)))
hWnd = NULL;
else
hWnd = (HWND)pProp->GetInt32();
WinHelp(hWnd, oHelpFile.c_str(), HELP_FINDER, FreeAmp_Main_Window);
#endif
#ifdef HAVE_GTK
struct _stat st;
if (_stat(oHelpFile.c_str(), &st) == 0 && st.st_mode & S_IFREG)
LaunchBrowser((char *)oHelpFile.c_str());
else
{
MessageDialog oBox(m_pContext);
string oMessage(szCantFindHelpError);
oBox.Show(oMessage.c_str(), string(BRANDING), kMessageOk, true);
}
#endif
}
void FreeAmpTheme::update_thread(void* arg)
{
FreeAmpTheme* _this = (FreeAmpTheme*)arg;
_this->UpdateThread();
}
void FreeAmpTheme::UpdateThread()
{
#ifdef WIN32
m_pUpdateMan->RetrieveLatestVersionInfo();
if(m_pUpdateMan->IsUpdateAvailable())
{
if(0 < DialogBoxParam(g_hinst,
MAKEINTRESOURCE(IDD_UPDATEAVAILABLE),
NULL,
(int (__stdcall *)(void))::UpdateAvailableDlgProc,
(LPARAM) 0))
{
ShowOptions(4);
}
}
#endif
delete m_pUpdateThread;
}
void FreeAmpTheme::ShowOptions(uint32 defaultPage)
{
OptionsArgs *oArgs = new OptionsArgs;
if (m_bInOptions)
return;
if (m_pOptionsThread)
{
delete m_pOptionsThread;
m_pOptionsThread = NULL;
}
oArgs->pThis = this;
oArgs->uDefaultPage = defaultPage;
m_pOptionsThread = Thread::CreateThread();
m_pOptionsThread->Create(options_thread, oArgs);
}
void FreeAmpTheme::options_thread(void* arg)
{
OptionsArgs *pArgs = (OptionsArgs *)arg;
pArgs->pThis->OptionsThread(pArgs->uDefaultPage);
delete pArgs;
}
void FreeAmpTheme::OptionsThread(uint32 defaultPage)
{
PreferenceWindow *pWindow;
m_bInOptions = true;
#ifdef WIN32
pWindow = new Win32PreferenceWindow(m_pContext, m_pThemeMan, m_pUpdateMan, defaultPage);
#elif defined(__BEOS__)
pWindow = new BeOSPreferenceWindow(m_pContext, m_pThemeMan);
#else
pWindow = new GTKPreferenceWindow(m_pContext, m_pThemeMan, defaultPage);
#endif
pWindow->Show(m_pWindow);
delete pWindow;
m_bInOptions = false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -