📄 win32musicbrowser.cpp
字号:
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
Portions Copyright (C) 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: Win32MusicBrowser.cpp,v 1.80 2001/02/27 22:03:26 robert Exp $
____________________________________________________________________________*/
// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disabled.
#ifdef WIN32
#pragma warning(disable:4786)
#endif
#include <windows.h>
#include <windowsx.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <direct.h>
#include <algorithm>
using namespace std;
#include "config.h"
#include "utility.h"
#include "resource.h"
#include "Win32MusicBrowser.h"
#include "debug.h"
#include "eventdata.h"
#include "MissingFileDialog.h"
#include "player.h"
HINSTANCE g_hinst = NULL;
const int iSpacer = 15;
#define DB Debug_v("%d", __LINE__);
const char *mbcdNotFoundMessage =
"This CD was not found in MusicBrainz. Would "
"you like to enter the information for this CD and submit "
"the data for inclusion in the MusicBrainz metadatabase?";
const char *dbaseUpgradedMessage =
"Due to internal changes, "the_BRANDING" has "
"modified the format of the database that stores the "
"My Music tree. Unfortunately, this means that you need "
"to search for music again to rebuild "the_BRANDING"'s "
"internal catalog.";
bool operator<(const TreeData &A, const TreeData &b)
{
assert(0);
return 0;
}
bool operator==(const TreeData &A, const TreeData &b)
{
assert(0);
return 0;
}
INT WINAPI DllMain (HINSTANCE hInstance,
ULONG ul_reason_being_called,
LPVOID lpReserved)
{
switch(ul_reason_being_called)
{
case DLL_PROCESS_ATTACH:
g_hinst = hInstance;
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return 1;
}
extern "C" {
UserInterface *Initialize(FAContext *context) {
return new MusicBrowserUI(context, NULL, NULL, string(""));
}
}
MusicBrowserUI::MusicBrowserUI(FAContext *context,
MusicBrowserUI *parent,
HWND hParent,
DeviceInfo *pDevice)
{
m_context = context;
m_pParent = parent;
m_hParent = hParent;
Init();
if (m_pParent == NULL)
m_plm = m_context->plm;
else
{
m_plm = new PlaylistManager(m_context);
m_portableDevice = pDevice;
string displayString;
displayString = pDevice->GetManufacturer();
displayString += " ";
displayString += pDevice->GetDevice();
if(displayString.size())
{
m_currentListName = displayString;
}
else
{
m_currentListName = pDevice->GetPluginName();
}
}
}
MusicBrowserUI::MusicBrowserUI(FAContext *context,
MusicBrowserUI *parent,
HWND hParent,
const string &oPlaylistName)
{
m_context = context;
m_pParent = parent;
m_hParent = hParent;
Init();
if(m_pParent == NULL)
{
m_plm = m_context->plm;
if(!m_plm->CountItems())
{
bool savePlaylist = true;
uint32 index = 0;
m_context->prefs->GetPrefBoolean(kSaveCurrentPlaylistOnExitPref, &savePlaylist);
m_context->prefs->GetPrefInt32(kSavedPlaylistPositionPref, (int32*)&index);
if(savePlaylist)
{
char path[MAX_PATH];
char url[MAX_PATH + 7];
uint32 length = sizeof(path);
m_context->prefs->GetPrefString(kInstallDirPref, path, &length);
strcat(path, "\\freeamp.m3u");
length = sizeof(url);
FilePathToURL(path, url, &length);
vector<PlaylistItem*> items;
m_plm->ReadPlaylist(url, &items);
m_initialCount = items.size();
m_autoPlayHack = true;
if(m_initialCount)
{
m_plm->AddItems(&items);
m_plm->SetCurrentIndex(index);
}
}
}
}
else
{
m_plm = new PlaylistManager(m_context);
m_currentListName = oPlaylistName;
}
}
void MusicBrowserUI::Init()
{
m_initialized = false;
isVisible = false;
m_currentListName = "";
m_state = STATE_EXPANDED;
m_hWnd = NULL;
m_sMinSize.x = -1;
m_bListChanged = false;
m_bSearchInProgress = false;
m_currentplaying = -1;
m_bDragging = false;
m_uiThread = NULL;
m_overSplitter = false;
m_trackSplitter = false;
m_plm = NULL;
m_portableDevice = NULL;
m_sigsExist = false;
m_sigsStart = true;
//
// Get the starting values of the columns.
unsigned int size = 100;
char *buffer = (char *)malloc( size );
if(kError_BufferTooSmall == m_context->prefs->GetPrefString(kPlaylistHeaderColumnsPref, buffer, &size))
{
int bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
m_context->prefs->GetPrefString(kPlaylistHeaderColumnsPref, buffer, &size);
}
m_columnCache = buffer;
free(buffer);
short pattern[8];
HBITMAP bmp;
for (int32 i = 0; i < 8; i++)
pattern[i] = (WORD)(0x5555 << (i & 1));
bmp = CreateBitmap(8, 8, 1, 1, &pattern);
m_splitterBrush = CreatePatternBrush(bmp);
DeleteObject(bmp);
m_hSplitterCursor = LoadCursor(g_hinst, MAKEINTRESOURCE(IDC_SPLITTER));
m_hPointerCursor = LoadCursor(NULL, IDC_ARROW);
m_hCurrentCursor = m_hPointerCursor;
m_playerState = PLAYERSTATE_STOPPED;
m_initialCount = 0;
m_itemsAddedBeforeWeWereCreated = 0;
m_hMusicView = NULL;
m_hPlaylistView = NULL;
m_hMyMusicItem = NULL;
m_hAllItem = NULL;
m_hUncatItem = NULL;
m_hPlaylistItem = NULL;
m_hNewPlaylistItem = NULL;
m_hStreamsItem = NULL;
m_hCDItem = NULL;
m_hFavoritesItem = NULL;
m_hNewFavoritesItem = NULL;
m_hMusicView = NULL;
m_hPortableItem = NULL;
m_hNewPortableItem = NULL;
m_autoPlayHack = false;
m_cdId = 0;
if(m_pParent == NULL)
m_cdTracks = new vector<PlaylistItem*>;
else
m_cdTracks = NULL;
m_streamsTimer = NULL;
m_fillAllThread = NULL;
m_fillStreamsThread = NULL;
}
MusicBrowserUI::~MusicBrowserUI()
{
DeleteObject(m_splitterBrush);
DestroyCursor(m_hSplitterCursor);
DestroyCursor(m_hPointerCursor);
if(m_streamsTimer)
m_context->timerManager->StopTimer(m_streamsTimer);
if (m_pParent)
{
delete m_plm;
if(m_cdTracks)
delete m_cdTracks;
}
else
{
vector<MusicBrowserUI *>::iterator i;
for(i = m_oWindowList.begin(); i != m_oWindowList.end(); i++)
delete (*i);
}
if(!m_pParent)
m_context->prefs->SetPrefBoolean(kViewMusicBrowserPref, m_state == STATE_EXPANDED);
CloseMainDialog();
delete m_uiThread;
}
// These two functions should never get called on non-parent music browsers
void MusicBrowserUI::AddMusicBrowserWindow(MusicBrowserUI *pWindow)
{
assert(m_pParent == NULL);
m_oWindowList.push_back(pWindow);
}
void MusicBrowserUI::RemoveMusicBrowserWindow(MusicBrowserUI *pWindow)
{
vector<MusicBrowserUI *>::iterator i;
assert(m_pParent == NULL);
i = find(m_oWindowList.begin(), m_oWindowList.end(), pWindow);
if (i != m_oWindowList.end())
m_oWindowList.erase(i);
}
Error MusicBrowserUI::Init(int32 startup_level)
{
if ((m_startupType = startup_level) != SECONDARY_UI_STARTUP) {
cout << "The musicbrowser cannot run as the primary ui\n";
return kError_InitFailedSafely;
}
m_playerEQ = m_context->target;
m_uiThread = Thread::CreateThread();
m_uiThread->Create(MusicBrowserUI::UIThreadFunc, this);
return kError_NoErr;
}
void MusicBrowserUI::MusicSearchDone()
{
HMENU hMenu;
MENUITEMINFO sItem;
SendMessage(m_hStatus, SB_SETTEXT, 0, (LPARAM)"Music search completed.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -