~ubuntu-branches/ubuntu/precise/guayadeque/precise

« back to all changes in this revision

Viewing changes to src/.svn/text-base/LocationPanel.cpp.svn-base

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-05-14 15:08:03 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110514150803-8b5evqetnaj35j34
Tags: 0.3.1~dfsg0-1
* New upstream release.
* Strip wxsqlite3 stuff out of upstream's tarballs.
* Update get-orig-source target in debian/rules.
* Update gbp config file.
* Bump Standards.
* Build-depend on libwxsqlite3-2.8-dev
* Enable parallel builds.
* Link binaries against the system-wide copy of wxsqlite3.
* Point sources to the correct wxcurl's headers location.
* Update copyright file as per DEP-5
* Improve debian/watch to handle the ~dfsg\d* suffix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -------------------------------------------------------------------------------- //
2
 
//      Copyright (C) 2008-2010 J.Rios
3
 
//      anonbeat@gmail.com
4
 
//
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)
8
 
//    any later version.
9
 
//
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.
14
 
//
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
19
 
//
20
 
// -------------------------------------------------------------------------------- //
21
 
#include "LocationPanel.h"
22
 
 
23
 
#include "Config.h"
24
 
#include "Images.h"
25
 
 
26
 
#include <wx/tokenzr.h>
27
 
#include <wx/artprov.h>
28
 
 
29
 
// -------------------------------------------------------------------------------- //
30
 
// guShoutcastItemData
31
 
// -------------------------------------------------------------------------------- //
32
 
class guLocationItemData : public wxTreeItemData
33
 
{
34
 
  private :
35
 
    int         m_Id;
36
 
    bool        m_IsOpen;
37
 
 
38
 
  public :
39
 
    guLocationItemData( const int id, const bool open )
40
 
    {
41
 
        m_Id = id;
42
 
        m_IsOpen = open;
43
 
    }
44
 
 
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; }
49
 
};
50
 
 
51
 
#define guLOCATION_PANEL_IMAGE_COUNT    9
52
 
 
53
 
// -------------------------------------------------------------------------------- //
54
 
// guLocationTreeCtrl
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 )
59
 
{
60
 
    m_MainFrame = mainframe;
61
 
    m_LockCount = 0;
62
 
 
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 ) );
73
 
 
74
 
    AssignImageList( m_ImageList );
75
 
 
76
 
    m_RootId   = AddRoot( wxT( "Sources" ), -1, -1, NULL );
77
 
 
78
 
    //SetIndent( 2 );
79
 
 
80
 
    wxFont FontBold = GetFont();
81
 
    FontBold.SetWeight( wxFONTWEIGHT_BOLD );
82
 
 
83
 
    m_MyMusicId = AppendItem( m_RootId, _( "My Music" ), 0, -1, NULL );
84
 
 
85
 
    m_PortableDeviceId = AppendItem( m_RootId, _( "Portable Devices" ), 1, -1, NULL );
86
 
 
87
 
    m_OnlineRadioId = AppendItem( m_RootId, _( "Radios" ), 2, -1, NULL );
88
 
 
89
 
    m_OnlineStoreId = AppendItem( m_RootId, _( "Stores" ), -1, -1, NULL );
90
 
 
91
 
    m_PodcastId = AppendItem( m_RootId, _( "Podcasts" ), 3, -1, new guLocationItemData( ID_MENU_VIEW_PODCASTS, false ) );
92
 
 
93
 
    m_ContextId = AppendItem( m_RootId, _( "Context" ), -1, -1, NULL );
94
 
 
95
 
    SetIndent( 5 );
96
 
 
97
 
    Connect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guLocationTreeCtrl::OnContextMenu ), NULL, this );
98
 
    Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( guLocationTreeCtrl::OnKeyDown ), NULL, this );
99
 
 
100
 
    ReloadItems( true );
101
 
}
102
 
 
103
 
// -------------------------------------------------------------------------------- //
104
 
guLocationTreeCtrl::~guLocationTreeCtrl()
105
 
{
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") );
111
 
 
112
 
    Disconnect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guLocationTreeCtrl::OnContextMenu ), NULL, this );
113
 
    Disconnect( wxEVT_KEY_DOWN, wxKeyEventHandler( guLocationTreeCtrl::OnKeyDown ), NULL, this );
114
 
}
115
 
 
116
 
// -------------------------------------------------------------------------------- //
117
 
void guLocationTreeCtrl::ReloadItems( const bool loadstate )
118
 
{
119
 
    if( m_LockCount )
120
 
        return;
121
 
 
122
 
    guLogMessage( wxT( "guLocationTreeCtrl::ReloadItems" ) );
123
 
    wxTreeItemId CurrentItem;
124
 
    int VisiblePanels = m_MainFrame->VisiblePanels();
125
 
 
126
 
    bool MyMusicExpanded;
127
 
    bool RadiosExpanded;
128
 
    bool StoresExpanded;
129
 
    bool ContextExpanded;
130
 
 
131
 
    if( loadstate )
132
 
    {
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") );
138
 
    }
139
 
    else
140
 
    {
141
 
        MyMusicExpanded = IsExpanded( m_MyMusicId );
142
 
        RadiosExpanded = IsExpanded( m_OnlineRadioId );
143
 
        StoresExpanded = IsExpanded( m_OnlineStoreId );
144
 
        ContextExpanded = IsExpanded( m_ContextId );
145
 
    }
146
 
 
147
 
    //
148
 
    // My Local Music Locations
149
 
    //
150
 
    DeleteChildren( m_MyMusicId );
151
 
 
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 );
166
 
 
167
 
    if( MyMusicExpanded )
168
 
        Expand( m_MyMusicId );
169
 
 
170
 
    //
171
 
    // Portable Device Locations
172
 
    //
173
 
    DeleteChildren( m_PortableDeviceId );
174
 
 
175
 
    wxArrayString VolumeNames = m_MainFrame->PortableDeviceVolumeNames();
176
 
    int Index;
177
 
    int Count = VolumeNames.Count();
178
 
    for( Index = 0; Index < Count; Index++ )
179
 
    {
180
 
        bool IconFound = false;
181
 
 
182
 
        int DeviceBaseCmd = ID_MENU_VIEW_PORTABLE_DEVICE + ( Index * guPORTABLEDEVICE_COMMANDS_COUNT );
183
 
        guPortableMediaViewCtrl * PortableMediaViewCtrl = m_MainFrame->GetPortableMediaViewCtrl( DeviceBaseCmd );
184
 
        if( PortableMediaViewCtrl )
185
 
        {
186
 
            wxString IconString = PortableMediaViewCtrl->IconString();
187
 
            if( !IconString.IsEmpty() )
188
 
            {
189
 
                //. GThemedIcon drive-removable-media-usb drive-removable-media drive-removable drive
190
 
                wxArrayString IconNames = wxStringTokenize( IconString, wxT( " " ) );
191
 
                int IconIndex;
192
 
                int IconCount = IconNames.Count();
193
 
                for( IconIndex = 0; IconIndex < IconCount; IconIndex++ )
194
 
                {
195
 
                    guLogMessage( wxT( "Trying to load the icon '%s'" ), IconNames[ IconIndex ].c_str() );
196
 
                    if( IconNames[ IconIndex ] == wxT( "." ) || IconNames[ IconIndex ] == wxT( "GThemedIcon" ) )
197
 
                        continue;
198
 
 
199
 
                    wxBitmap IconBitmap = wxArtProvider::GetBitmap( IconNames[ IconIndex ], wxART_OTHER, wxSize( 24, 24 ) );
200
 
                    if( IconBitmap.IsOk() )
201
 
                    {
202
 
                        guLogMessage( wxT( "The Icon was found...") );
203
 
                        int IconPos = m_IconNames.Index( IconNames[ IconIndex ] );
204
 
                        if( IconPos == wxNOT_FOUND )
205
 
                        {
206
 
                            IconPos = m_IconNames.Count();
207
 
                            m_IconNames.Add( IconNames[ IconIndex ] );
208
 
                            m_ImageList->Add( IconBitmap );
209
 
                        }
210
 
                        CurrentItem = AppendItem( m_PortableDeviceId, VolumeNames[ Index ], IconPos + guLOCATION_PANEL_IMAGE_COUNT, -1, NULL );
211
 
                        IconFound = true;
212
 
                        break;
213
 
                    }
214
 
                }
215
 
            }
216
 
        }
217
 
 
218
 
        if( !IconFound )
219
 
        {
220
 
            CurrentItem = AppendItem( m_PortableDeviceId, VolumeNames[ Index ], -1, -1, new guLocationItemData( DeviceBaseCmd, PortableMediaViewCtrl ) );
221
 
        }
222
 
 
223
 
        if( PortableMediaViewCtrl )
224
 
        {
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 );
238
 
        }
239
 
 
240
 
        //BaseCmd = ID_MENU_VIEW_PORTABLE_DEVICE + ( Index * guPORTABLEDEVICE_COMMANDS_COUNT );
241
 
        //CreatePortableMediaDeviceMenu( menu, VolumeNames[ Index ], BaseCmd );
242
 
    }
243
 
 
244
 
    Expand( m_PortableDeviceId );
245
 
 
246
 
    //
247
 
    // Online Radio Locations
248
 
    //
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 );
253
 
 
254
 
    if( RadiosExpanded )
255
 
        Expand( m_OnlineRadioId );
256
 
 
257
 
    //
258
 
    // Online Stores Locations
259
 
    //
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 );
267
 
    if( StoresExpanded )
268
 
        Expand( m_OnlineStoreId );
269
 
 
270
 
    //
271
 
    // Podcasts Locations
272
 
    //
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() );
277
 
 
278
 
 
279
 
    //
280
 
    // Context Locations
281
 
    //
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 );
286
 
 
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 );
292
 
 
293
 
 
294
 
}
295
 
 
296
 
// -------------------------------------------------------------------------------- //
297
 
void guLocationTreeCtrl::OnContextMenu( wxTreeEvent &event )
298
 
{
299
 
    event.Skip();
300
 
}
301
 
 
302
 
// -------------------------------------------------------------------------------- //
303
 
void guLocationTreeCtrl::OnKeyDown( wxKeyEvent &event )
304
 
{
305
 
    event.Skip();
306
 
}
307
 
 
308
 
 
309
 
 
310
 
 
311
 
// -------------------------------------------------------------------------------- //
312
 
// guLocationPanel
313
 
// -------------------------------------------------------------------------------- //
314
 
guLocationPanel::guLocationPanel( wxWindow * parent ) :
315
 
    wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL )
316
 
{
317
 
    m_MainFrame = ( guMainFrame * ) parent;
318
 
 
319
 
    wxBoxSizer * MainSizer = new wxBoxSizer( wxVERTICAL );
320
 
 
321
 
    m_LocationTreeCtrl = new guLocationTreeCtrl( this, m_MainFrame );
322
 
    MainSizer->Add( m_LocationTreeCtrl, 1, wxEXPAND, 5 );
323
 
 
324
 
        SetSizer( MainSizer );
325
 
        Layout();
326
 
        MainSizer->Fit( this );
327
 
 
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 );
330
 
}
331
 
 
332
 
// -------------------------------------------------------------------------------- //
333
 
guLocationPanel::~guLocationPanel()
334
 
{
335
 
}
336
 
 
337
 
// -------------------------------------------------------------------------------- //
338
 
void guLocationPanel::OnPortableDeviceChanged( void )
339
 
{
340
 
    m_LocationTreeCtrl->ReloadItems();
341
 
}
342
 
 
343
 
// -------------------------------------------------------------------------------- //
344
 
void guLocationPanel::OnPanelVisibleChanged( void )
345
 
{
346
 
    m_LocationTreeCtrl->ReloadItems();
347
 
}
348
 
 
349
 
// -------------------------------------------------------------------------------- //
350
 
void guLocationPanel::OnLocationItemActivated( wxTreeEvent &event )
351
 
{
352
 
    wxTreeItemId ItemId = event.GetItem();
353
 
    guLocationItemData * ItemData = ( guLocationItemData * ) m_LocationTreeCtrl->GetItemData( ItemId );
354
 
    if( ItemData )
355
 
    {
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 );
360
 
    }
361
 
    event.Skip();
362
 
}
363
 
 
364
 
// -------------------------------------------------------------------------------- //
365
 
void guLocationPanel::OnLocationItemChanged( wxTreeEvent &event )
366
 
{
367
 
    wxTreeItemId ItemId = event.GetItem();
368
 
    guLocationItemData * ItemData = ( guLocationItemData * ) m_LocationTreeCtrl->GetItemData( ItemId );
369
 
    if( ItemData )
370
 
    {
371
 
        if( ItemData->GetOpen() && ItemData->GetId() )
372
 
        {
373
 
            wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_MAINFRAME_SELECT_LOCATION );
374
 
            event.SetInt( ItemData->GetId() );
375
 
            wxPostEvent( m_MainFrame, event );
376
 
        }
377
 
    }
378
 
    event.Skip();
379
 
}
380
 
 
381
 
// -------------------------------------------------------------------------------- //