1
// -------------------------------------------------------------------------------- //
2
// Copyright (C) 2008-2010 J.Rios
5
// This Program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2, or (at your option)
10
// This Program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; see the file LICENSE. If not, write to
17
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
// http://www.gnu.org/copyleft/gpl.html
20
// -------------------------------------------------------------------------------- //
21
#include "LocationPanel.h"
26
#include <wx/tokenzr.h>
27
#include <wx/artprov.h>
29
// -------------------------------------------------------------------------------- //
30
// guShoutcastItemData
31
// -------------------------------------------------------------------------------- //
32
class guLocationItemData : public wxTreeItemData
39
guLocationItemData( const int id, const bool open )
45
int GetId( void ) { return m_Id; }
46
void SetId( int id ) { m_Id = id; }
47
int GetOpen( void ) { return m_IsOpen; }
48
void SetOpen( const bool open ) { m_IsOpen = open; }
51
#define guLOCATION_PANEL_IMAGE_COUNT 9
53
// -------------------------------------------------------------------------------- //
55
// -------------------------------------------------------------------------------- //
56
guLocationTreeCtrl::guLocationTreeCtrl( wxWindow * parent, guMainFrame * mainframe ) :
57
wxTreeCtrl( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
58
wxTR_DEFAULT_STYLE|wxTR_SINGLE|wxTR_HIDE_ROOT|wxTR_FULL_ROW_HIGHLIGHT )
60
m_MainFrame = mainframe;
63
m_ImageList = new wxImageList();
64
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_library ) );
65
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_portable_device ) );
66
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_net_radio ) );
67
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_podcast ) );
68
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_magnatune ) );
69
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_jamendo ) );
70
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_lastfm ) );
71
m_ImageList->Add( guImage( guIMAGE_INDEX_tiny_shoutcast ) );
72
m_ImageList->Add( guImage( guIMAGE_INDEX_loc_lyrics ) );
74
AssignImageList( m_ImageList );
76
m_RootId = AddRoot( wxT( "Sources" ), -1, -1, NULL );
80
wxFont FontBold = GetFont();
81
FontBold.SetWeight( wxFONTWEIGHT_BOLD );
83
m_MyMusicId = AppendItem( m_RootId, _( "My Music" ), 0, -1, NULL );
85
m_PortableDeviceId = AppendItem( m_RootId, _( "Portable Devices" ), 1, -1, NULL );
87
m_OnlineRadioId = AppendItem( m_RootId, _( "Radios" ), 2, -1, NULL );
89
m_OnlineStoreId = AppendItem( m_RootId, _( "Stores" ), -1, -1, NULL );
91
m_PodcastId = AppendItem( m_RootId, _( "Podcasts" ), 3, -1, new guLocationItemData( ID_MENU_VIEW_PODCASTS, false ) );
93
m_ContextId = AppendItem( m_RootId, _( "Context" ), -1, -1, NULL );
97
Connect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guLocationTreeCtrl::OnContextMenu ), NULL, this );
98
Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( guLocationTreeCtrl::OnKeyDown ), NULL, this );
103
// -------------------------------------------------------------------------------- //
104
guLocationTreeCtrl::~guLocationTreeCtrl()
106
guConfig * Config = ( guConfig * ) guConfig::Get();
107
Config->WriteBool( wxT( "MyMusicExpanded" ), IsExpanded( m_MyMusicId ), wxT( "MainSources") );
108
Config->WriteBool( wxT( "RadiosExpanded" ), IsExpanded( m_OnlineRadioId ), wxT( "MainSources") );
109
Config->WriteBool( wxT( "StoresExpanded" ), IsExpanded( m_OnlineStoreId ), wxT( "MainSources") );
110
Config->WriteBool( wxT( "ContextExpanded" ), IsExpanded( m_ContextId ), wxT( "MainSources") );
112
Disconnect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guLocationTreeCtrl::OnContextMenu ), NULL, this );
113
Disconnect( wxEVT_KEY_DOWN, wxKeyEventHandler( guLocationTreeCtrl::OnKeyDown ), NULL, this );
116
// -------------------------------------------------------------------------------- //
117
void guLocationTreeCtrl::ReloadItems( const bool loadstate )
122
guLogMessage( wxT( "guLocationTreeCtrl::ReloadItems" ) );
123
wxTreeItemId CurrentItem;
124
int VisiblePanels = m_MainFrame->VisiblePanels();
126
bool MyMusicExpanded;
129
bool ContextExpanded;
133
guConfig * Config = ( guConfig * ) guConfig::Get();
134
MyMusicExpanded = Config->ReadBool( wxT( "MyMusicExpanded" ), true, wxT( "MainSources") );
135
RadiosExpanded = Config->ReadBool( wxT( "RadiosExpanded" ), true, wxT( "MainSources") );
136
StoresExpanded = Config->ReadBool( wxT( "StoresExpanded" ), true, wxT( "MainSources") );
137
ContextExpanded = Config->ReadBool( wxT( "ContextExpanded" ), true, wxT( "MainSources") );
141
MyMusicExpanded = IsExpanded( m_MyMusicId );
142
RadiosExpanded = IsExpanded( m_OnlineRadioId );
143
StoresExpanded = IsExpanded( m_OnlineStoreId );
144
ContextExpanded = IsExpanded( m_ContextId );
148
// My Local Music Locations
150
DeleteChildren( m_MyMusicId );
152
wxFont BoldFont = GetFont();
153
BoldFont.SetWeight( wxFONTWEIGHT_BOLD );
154
CurrentItem = AppendItem( m_MyMusicId, _( "Library" ), -1, -1, new guLocationItemData( ID_MENU_VIEW_LIBRARY, ( VisiblePanels & guPANEL_MAIN_LIBRARY ) ) );
155
if( VisiblePanels & guPANEL_MAIN_LIBRARY )
156
SetItemFont( CurrentItem, BoldFont );
157
CurrentItem = AppendItem( m_MyMusicId, _( "Playlists" ), -1, -1, new guLocationItemData( ID_MENU_VIEW_PLAYLISTS, ( VisiblePanels & guPANEL_MAIN_PLAYLISTS ) ) );
158
if( VisiblePanels & guPANEL_MAIN_PLAYLISTS )
159
SetItemFont( CurrentItem, BoldFont );
160
CurrentItem = AppendItem( m_MyMusicId, _( "Album Browser" ), -1, -1, new guLocationItemData( ID_MENU_VIEW_ALBUMBROWSER, ( VisiblePanels & guPANEL_MAIN_ALBUMBROWSER ) ) );
161
if( VisiblePanels & guPANEL_MAIN_ALBUMBROWSER )
162
SetItemFont( CurrentItem, BoldFont );
163
CurrentItem = AppendItem( m_MyMusicId, _( "File Browser" ), -1, -1, new guLocationItemData( ID_MENU_VIEW_FILEBROWSER, ( VisiblePanels & guPANEL_MAIN_FILEBROWSER ) ) );
164
if( VisiblePanels & guPANEL_MAIN_FILEBROWSER )
165
SetItemFont( CurrentItem, BoldFont );
167
if( MyMusicExpanded )
168
Expand( m_MyMusicId );
171
// Portable Device Locations
173
DeleteChildren( m_PortableDeviceId );
175
wxArrayString VolumeNames = m_MainFrame->PortableDeviceVolumeNames();
177
int Count = VolumeNames.Count();
178
for( Index = 0; Index < Count; Index++ )
180
bool IconFound = false;
182
int DeviceBaseCmd = ID_MENU_VIEW_PORTABLE_DEVICE + ( Index * guPORTABLEDEVICE_COMMANDS_COUNT );
183
guPortableMediaViewCtrl * PortableMediaViewCtrl = m_MainFrame->GetPortableMediaViewCtrl( DeviceBaseCmd );
184
if( PortableMediaViewCtrl )
186
wxString IconString = PortableMediaViewCtrl->IconString();
187
if( !IconString.IsEmpty() )
189
//. GThemedIcon drive-removable-media-usb drive-removable-media drive-removable drive
190
wxArrayString IconNames = wxStringTokenize( IconString, wxT( " " ) );
192
int IconCount = IconNames.Count();
193
for( IconIndex = 0; IconIndex < IconCount; IconIndex++ )
195
guLogMessage( wxT( "Trying to load the icon '%s'" ), IconNames[ IconIndex ].c_str() );
196
if( IconNames[ IconIndex ] == wxT( "." ) || IconNames[ IconIndex ] == wxT( "GThemedIcon" ) )
199
wxBitmap IconBitmap = wxArtProvider::GetBitmap( IconNames[ IconIndex ], wxART_OTHER, wxSize( 24, 24 ) );
200
if( IconBitmap.IsOk() )
202
guLogMessage( wxT( "The Icon was found...") );
203
int IconPos = m_IconNames.Index( IconNames[ IconIndex ] );
204
if( IconPos == wxNOT_FOUND )
206
IconPos = m_IconNames.Count();
207
m_IconNames.Add( IconNames[ IconIndex ] );
208
m_ImageList->Add( IconBitmap );
210
CurrentItem = AppendItem( m_PortableDeviceId, VolumeNames[ Index ], IconPos + guLOCATION_PANEL_IMAGE_COUNT, -1, NULL );
220
CurrentItem = AppendItem( m_PortableDeviceId, VolumeNames[ Index ], -1, -1, new guLocationItemData( DeviceBaseCmd, PortableMediaViewCtrl ) );
223
if( PortableMediaViewCtrl )
225
SetItemFont( CurrentItem, BoldFont );
226
wxTreeItemId CurrentSubItem;
227
int VisiblePanels = PortableMediaViewCtrl->VisiblePanels();
228
CurrentSubItem = AppendItem( CurrentItem, _( "Library" ), -1, -1, new guLocationItemData( DeviceBaseCmd, ( VisiblePanels & guPANEL_MAIN_LIBRARY ) ) );
229
if( VisiblePanels & guPANEL_MAIN_LIBRARY )
230
SetItemFont( CurrentSubItem, BoldFont );
231
CurrentSubItem = AppendItem( CurrentItem, _( "Playlists" ), -1, -1, new guLocationItemData( DeviceBaseCmd + 18, ( VisiblePanels & guPANEL_MAIN_PLAYLISTS ) ) );
232
if( VisiblePanels & guPANEL_MAIN_PLAYLISTS )
233
SetItemFont( CurrentSubItem, BoldFont );
234
CurrentSubItem = AppendItem( CurrentItem, _( "Album Browser" ), -1, -1, new guLocationItemData( DeviceBaseCmd + 19, ( VisiblePanels & guPANEL_MAIN_ALBUMBROWSER ) ) );
235
if( VisiblePanels & guPANEL_MAIN_ALBUMBROWSER )
236
SetItemFont( CurrentSubItem, BoldFont );
237
Expand( CurrentItem );
240
//BaseCmd = ID_MENU_VIEW_PORTABLE_DEVICE + ( Index * guPORTABLEDEVICE_COMMANDS_COUNT );
241
//CreatePortableMediaDeviceMenu( menu, VolumeNames[ Index ], BaseCmd );
244
Expand( m_PortableDeviceId );
247
// Online Radio Locations
249
DeleteChildren( m_OnlineRadioId );
250
CurrentItem = AppendItem( m_OnlineRadioId, _( "Shoutcast" ), 7, -1, new guLocationItemData( ID_MENU_VIEW_RADIO, ( VisiblePanels & guPANEL_MAIN_RADIOS ) ) );
251
if( VisiblePanels & guPANEL_MAIN_RADIOS )
252
SetItemFont( CurrentItem, BoldFont );
255
Expand( m_OnlineRadioId );
258
// Online Stores Locations
260
DeleteChildren( m_OnlineStoreId );
261
CurrentItem = AppendItem( m_OnlineStoreId, _( "Magnatune" ), 4, -1, new guLocationItemData( ID_MENU_VIEW_MAGNATUNE, ( VisiblePanels & guPANEL_MAIN_MAGNATUNE ) ) );
262
if( VisiblePanels & guPANEL_MAIN_MAGNATUNE )
263
SetItemFont( CurrentItem, BoldFont );
264
CurrentItem = AppendItem( m_OnlineStoreId, _( "Jamendo" ), 5, -1, new guLocationItemData( ID_MENU_VIEW_JAMENDO, ( VisiblePanels & guPANEL_MAIN_JAMENDO ) ) );
265
if( VisiblePanels & guPANEL_MAIN_JAMENDO )
266
SetItemFont( CurrentItem, BoldFont );
268
Expand( m_OnlineStoreId );
271
// Podcasts Locations
273
//DeleteChildren( m_PodcastId );
274
guLocationItemData * PodcastItemData = ( guLocationItemData * ) GetItemData( m_PodcastId );
275
PodcastItemData->SetOpen( ( VisiblePanels & guPANEL_MAIN_PODCASTS ) );
276
SetItemFont( m_PodcastId, ( VisiblePanels & guPANEL_MAIN_PODCASTS ) ? BoldFont : GetFont() );
282
DeleteChildren( m_ContextId );
283
CurrentItem = AppendItem( m_ContextId, wxT( "Last.fm" ), 6, -1, new guLocationItemData( ID_MENU_VIEW_LASTFM, ( VisiblePanels & guPANEL_MAIN_LASTFM ) ) );
284
if( VisiblePanels & guPANEL_MAIN_LASTFM )
285
SetItemFont( CurrentItem, BoldFont );
287
CurrentItem = AppendItem( m_ContextId, _( "Lyrics" ), 8, -1, new guLocationItemData( ID_MENU_VIEW_LYRICS, ( VisiblePanels & guPANEL_MAIN_LYRICS ) ) );
288
if( VisiblePanels & guPANEL_MAIN_LYRICS )
289
SetItemFont( CurrentItem, BoldFont );
290
if( ContextExpanded )
291
Expand( m_ContextId );
296
// -------------------------------------------------------------------------------- //
297
void guLocationTreeCtrl::OnContextMenu( wxTreeEvent &event )
302
// -------------------------------------------------------------------------------- //
303
void guLocationTreeCtrl::OnKeyDown( wxKeyEvent &event )
311
// -------------------------------------------------------------------------------- //
313
// -------------------------------------------------------------------------------- //
314
guLocationPanel::guLocationPanel( wxWindow * parent ) :
315
wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL )
317
m_MainFrame = ( guMainFrame * ) parent;
319
wxBoxSizer * MainSizer = new wxBoxSizer( wxVERTICAL );
321
m_LocationTreeCtrl = new guLocationTreeCtrl( this, m_MainFrame );
322
MainSizer->Add( m_LocationTreeCtrl, 1, wxEXPAND, 5 );
324
SetSizer( MainSizer );
326
MainSizer->Fit( this );
328
m_LocationTreeCtrl->Connect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( guLocationPanel::OnLocationItemActivated ), NULL, this );
329
m_LocationTreeCtrl->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( guLocationPanel::OnLocationItemChanged ), NULL, this );
332
// -------------------------------------------------------------------------------- //
333
guLocationPanel::~guLocationPanel()
337
// -------------------------------------------------------------------------------- //
338
void guLocationPanel::OnPortableDeviceChanged( void )
340
m_LocationTreeCtrl->ReloadItems();
343
// -------------------------------------------------------------------------------- //
344
void guLocationPanel::OnPanelVisibleChanged( void )
346
m_LocationTreeCtrl->ReloadItems();
349
// -------------------------------------------------------------------------------- //
350
void guLocationPanel::OnLocationItemActivated( wxTreeEvent &event )
352
wxTreeItemId ItemId = event.GetItem();
353
guLocationItemData * ItemData = ( guLocationItemData * ) m_LocationTreeCtrl->GetItemData( ItemId );
356
guLogMessage( wxT( "Sending the event %i" ), ItemData->GetId() );
357
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ItemData->GetId() );
358
event.SetInt( !ItemData->GetOpen() );
359
wxPostEvent( m_MainFrame, event );
364
// -------------------------------------------------------------------------------- //
365
void guLocationPanel::OnLocationItemChanged( wxTreeEvent &event )
367
wxTreeItemId ItemId = event.GetItem();
368
guLocationItemData * ItemData = ( guLocationItemData * ) m_LocationTreeCtrl->GetItemData( ItemId );
371
if( ItemData->GetOpen() && ItemData->GetId() )
373
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_MAINFRAME_SELECT_LOCATION );
374
event.SetInt( ItemData->GetId() );
375
wxPostEvent( m_MainFrame, event );
381
// -------------------------------------------------------------------------------- //