📄 beosmusicbrowser.cpp
字号:
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
Portions Copyright (C) 1999, 2000 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: BeOSMusicBrowser.cpp,v 1.6 2000/07/17 22:31:03 hiro Exp $
____________________________________________________________________________*/
#include "BeOSMusicBrowser.h"
#include "MusicBrowserUI.h"
#include "ToolBar.h"
#include "ToolBarButton.h"
#include "Separator.h"
#include "Placard.h"
#include "MusicTreeView.h"
#include "PlaylistView.h"
#include "TooltipFilter.h"
#include "TrackItem.h"
#include "CollectionItem.h"
#include "PlaylistListItem.h"
#include "ResourceManager.h"
#include "MusicBrowserResources.h"
#include "IntroductionWizard.h"
#include "InfoEditor.h"
#include "event.h"
#include "eventdata.h"
#include "musiccatalog.h"
#include "playlist.h"
#include <be/interface/Button.h>
#include <be/interface/ScrollView.h>
#include <be/interface/MenuBar.h>
#include <be/interface/MenuItem.h>
#include <be/interface/Bitmap.h>
#include <be/interface/StringView.h>
#include <be/translation/TranslatorFormats.h>
#include <be/storage/FilePanel.h>
#include <be/storage/Entry.h>
#include <be/storage/Path.h>
#include <string>
#include <vector>
#define DEBUG 1
#include <be/support/Debug.h>
#define DEBUG_MENU 1
const char* MENU_LABEL_START_SEARCH = "Search Computer for Music";
const char* MENU_LABEL_STOP_SEARCH = "Stop Music Search";
BeOSMusicBrowser::BeOSMusicBrowser( FAContext* context, MusicBrowserUI* ui,
const string& playlistURL, bool master )
: BWindow( BRect( 10, 200, 400, 500 ), "Music Browser",
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 0 ),
m_context( context ),
m_plm( NULL ),
m_ui( ui ),
m_master( master ),
m_selectedView( NULL )
{
if ( m_master )
{
PRINT(( "i'm the master.\n" ));
m_plm = m_context->plm;
}
else
{
PRINT(( "i'm not the master.\n" ));
m_plm = new PlaylistManager( m_context );
LoadPlaylist( playlistURL );
}
InitViews();
}
BeOSMusicBrowser::~BeOSMusicBrowser()
{
}
void
BeOSMusicBrowser::InitViews( void )
{
float separator = Bounds().Width() * 0.4;
const float TOOL_BAR_HEIGHT = 42;
BRect rect;
BStringView* label;
BView* left;
BView* right;
TooltipFilter* tip;
rect = Bounds();
BMenuBar* topMenu = new BMenuBar( rect, "TopMenu" );
AddChild( topMenu );
BuildMenu( topMenu );
// Tool bar.
rect = Bounds();
rect.top = topMenu->Frame().bottom + 1;
rect.bottom = rect.top + TOOL_BAR_HEIGHT;
ToolBar* toolBar = new ToolBar( rect, "ToolBar",
B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT );
AddChild( toolBar );
BuildToolBar( toolBar );
// Separator.
rect = Bounds();
rect.top = toolBar->Frame().bottom + 1;
rect.left = separator + 1;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT - 2;
Separator* sep = new Separator( rect, "Separator",
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM );
sep->ResizeToPreferred();
AddChild( sep );
// Static string labels.
rect = Bounds();
rect.top = toolBar->Frame().bottom + 1;
rect.right = separator;
label = new BStringView( rect, "My Music Collection",
"My Music Collection" );
label->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
label->SetLowColor( label->ViewColor() );
font_height fontHeight;
label->GetFontHeight( &fontHeight );
label->ResizeTo( rect.Width(),
fontHeight.ascent + fontHeight.descent + 2 );
AddChild( label );
left = label;
rect = Bounds();
rect.top = toolBar->Frame().bottom + 1;
rect.left = sep->Frame().right + 1;
rect.bottom = rect.top + fontHeight.ascent + fontHeight.descent + 2;
label = new BStringView( rect, "PlaylistViewLabel",
m_master ? "Currently Listening To"
: "Editting",
B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT );
label->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
label->SetLowColor( label->ViewColor() );
AddChild( label );
right = label;
sep->AddAttachment( left, right );
// My Music tree
rect = Bounds();
//rect.top = toolBar->Frame().bottom + 1;
rect.top = label->Frame().bottom + 1;
rect.right = separator;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
rect.top += 2;
rect.right -= B_V_SCROLL_BAR_WIDTH + 2;
m_musicTreeView = new MusicTreeView( rect, "MusicTreeView",
B_SINGLE_SELECTION_LIST,
B_FOLLOW_ALL );
m_musicTreeView->
SetInvocationMessage( new BMessage( MBMSG_MUSIC_TREE_INVOKED ) );
tip = new TooltipFilter( new BMessage( MBMSG_TOOLTIP_MESSAGE ),
"Double click to add to the current playlist" );
m_musicTreeView->AddFilter( tip );
left = new BScrollView( "scroll", m_musicTreeView,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, 0,
false, true, B_FANCY_BORDER );
AddChild( left );
// Current playlist view
rect = Bounds();
rect.top = label->Frame().bottom + 1;
rect.left = sep->Frame().right + 1;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
// for scroll view
rect.top += 2;
rect.left += 2;
rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
m_playlistView =
new PlaylistView( this, rect, "PlaylistView", B_FOLLOW_ALL );
m_playlistView->
SetInvocationMessage( new BMessage( MBMSG_PLAYLIST_VIEW_INVOKED ) );
right = new BScrollView( "scroll", m_playlistView, B_FOLLOW_ALL,
false, true, B_FANCY_BORDER );
AddChild( right );
sep->AddAttachment( left, right );
// Placard (also acts as a tooltips placeholder)
rect = Bounds();
rect.top = rect.bottom - B_H_SCROLL_BAR_HEIGHT + 2 + 1;
rect.right -= B_V_SCROLL_BAR_WIDTH;
m_placard = new Placard( rect, "Placard",
B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT );
m_placard->SetText( "Welcome to Music Browser" );
AddChild( m_placard );
UpdateCatalogView();
UpdatePlaylistView();
}
void
BeOSMusicBrowser::MenusBeginning( void )
{
if ( m_ui->IsSearching() )
{
m_searchControl->SetLabel( MENU_LABEL_STOP_SEARCH );
m_searchControl->SetMessage( new BMessage( MBMSG_STOP_SEARCH ) );
}
else
{
m_searchControl->SetLabel( MENU_LABEL_START_SEARCH );
m_searchControl->SetMessage( new BMessage( MBMSG_SEARCH_DIALOG ) );
}
}
void
BeOSMusicBrowser::MessageReceived( BMessage* message )
{
switch ( message->what )
{
case MBMSG_UPDATE_MUSIC_CATALOG_VIEW:
UpdateCatalogView();
break;
case MBMSG_UPDATE_PLAYLIST_VIEW:
UpdatePlaylistView();
break;
case MBMSG_ADD_FILES:
{
BFilePanel* filePanel =
new BFilePanel( B_OPEN_PANEL,
new BMessenger( this ),
NULL, // panel_directory
B_FILE_NODE,
true, // allow_multiple_selection
NULL // message to be set below
);
BMessage reply( MBMSG_ADD_FILES_REPLY );
reply.AddPointer( "file_panel", filePanel );
filePanel->SetMessage( &reply ); // message copied by file panel
filePanel->Show();
break;
}
case MBMSG_ADD_FILES_REPLY:
{
vector<string> files;
int32 countFound = 0;
type_code typeFound;
message->GetInfo( "refs", &typeFound, &countFound );
for ( int32 i = 0; i < countFound; i++ )
{
entry_ref ref;
if ( message->FindRef( "refs", i, &ref ) == B_OK )
{
BEntry entry( &ref );
if ( entry.InitCheck() == B_OK )
{
BPath path;
if ( entry.GetPath( &path ) == B_OK )
{
files.push_back( string( path.Path() ) );
}
}
}
}
m_ui->AddFiles( files );
// then delete the file panel.
BFilePanel* filePanel;
if ( message->FindPointer( "file_panel", (void**)&filePanel )
== B_OK )
{
delete filePanel;
}
break;
}
case MBMSG_SEARCH_DIALOG:
case MBMSG_INTRO_WIZARD:
{
m_wizard = new IntroductionWizard( BRect( 100, 200, 600, 600 ),
"Search Music", m_ui, m_context );
m_wizard->Show();
break;
}
case MBMSG_WIZARD_GONE:
m_wizard = NULL;
break;
case MBMSG_STOP_SEARCH:
m_context->catalog->StopSearchMusic();
break;
case MBMSG_SEARCH_MUSIC_DONE:
if ( m_wizard )
{
m_wizard->PostMessage( MBMSG_SEARCH_MUSIC_DONE );
}
PostMessage( MBMSG_UPDATE_MUSIC_CATALOG_VIEW );
break;
case MBMSG_PLAYLIST_CURRENT_ITEM_INFO:
m_playlistView->SetCurrentlyPlaying(
message->FindInt32( "index" ) );
break;
case MBMSG_PLAYLIST_ITEM_REMOVED:
{
PlaylistItemRemovedEvent* pire;
if ( message->FindPointer( "event", (void**)&pire ) == B_OK &&
pire->Manager() == m_plm )
{
UpdatePlaylistView();
}
break;
}
case MBMSG_PLAYLIST_ITEMS_UPDATED:
{
PlaylistItemsUpdatedEvent* piue;
if ( message->FindPointer( "event", (void**)&piue ) == B_OK &&
piue->Manager() == m_plm )
{
UpdatePlaylistView();
}
break;
}
case MBMSG_PLAYLIST_SORTED:
{
PlaylistSortedEvent* pse;
if ( message->FindPointer( "event", (void**)&pse ) == B_OK &&
pse->Manager() == m_plm )
{
UpdatePlaylistView();
}
break;
}
case MBMSG_PLAYLIST_UPDATED: // not used?
UpdatePlaylistView();
break;
case MBMSG_MUSIC_CATALOG_PLAYLIST_ADDED:
case MBMSG_MUSIC_CATALOG_PLAYLIST_REMOVED:
UpdateCatalogPlaylistGroup();
break;
case MBMSG_CREATE_NEW_PLAYLIST:
m_ui->CreateNewEditor( string( "" ) );
break;
case MBMSG_SAVE_CURRENT_PLAYLIST:
if ( !m_master && m_currentListName.length() > 0 )
{
SaveCurrentPlaylist( NULL );
}
else
{
SaveCurrentPlaylistPanel( message, false );
}
break;
case MBMSG_SAVE_CURRENT_PLAYLIST_AS:
SaveCurrentPlaylistPanel( message, false );
break;
case MBMSG_SAVE_CURRENT_PLAYLIST_REPLY:
SaveCurrentPlaylistPanel( message, true );
break;
case MBMSG_IMPORT_ITEMS:
break;
case MBMSG_MUSIC_TREE_INVOKED:
{
PRINT(( "invoked" ));
int32 index = message->FindInt32( "index" );
CatalogItem* item = dynamic_cast<CatalogItem*>
( m_musicTreeView->ItemAt( index ) );
if ( item )
{
CatalogItemInvoked( item );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -