1
// -------------------------------------------------------------------------------- //
2
// Copyright (C) 2008-2011 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 3, 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
// -------------------------------------------------------------------------------- //
24
#include "AlbumBrowser.h"
25
#include "AuiNotebook.h"
27
#include "CoverPanel.h"
28
#include "curl/http.h"
29
#include "dbus/gudbus.h"
30
#include "dbus/mpris.h"
31
#include "dbus/mpris2.h"
32
#include "dbus/mmkeys.h"
33
#include "dbus/gsession.h"
34
#include "dbus/notify.h"
35
#include "DbLibrary.h"
37
#include "FileBrowser.h"
40
#include "LastFMPanel.h"
42
#include "GIO_Volume.h"
43
#include "LyricsPanel.h"
44
#include "Magnatune.h"
45
#include "PlayerFilters.h"
46
#include "PlayerPanel.h"
47
#include "PlayListPanel.h"
48
#include "PodcastsPanel.h"
49
#include "PortableMedia.h"
50
#include "RadioPanel.h"
51
#include "StatusBar.h"
52
#include "SplashWin.h"
53
#include "TreePanel.h"
56
#include <wx/aui/aui.h>
58
#include <wx/splitter.h>
60
#include <wx/sstream.h>
62
#include <wx/xml/xml.h>
63
#include <wx/zstream.h>
65
#ifdef WITH_LIBINDICATE_SUPPORT
67
#define GUAYADEQUE_INDICATOR_NAME "music.guayadeque"
68
#define GUAYADEQUE_DESKTOP_PATH "/usr/share/applications/guayadeque.desktop"
70
#include "libindicate/server.h"
71
#include "libindicate/indicator.h"
72
//#include "libindicate-gtk/indicator.h"
76
#define guPANEL_MAIN_PLAYERPLAYLIST ( 1 << 0 )
77
#define guPANEL_MAIN_PLAYERFILTERS ( 1 << 1 )
78
#define guPANEL_MAIN_PLAYERVUMETERS ( 1 << 2 )
79
#define guPANEL_MAIN_LIBRARY ( 1 << 3 )
80
#define guPANEL_MAIN_RADIOS ( 1 << 4 )
81
#define guPANEL_MAIN_LASTFM ( 1 << 5 )
82
#define guPANEL_MAIN_LYRICS ( 1 << 6 )
83
#define guPANEL_MAIN_PLAYLISTS ( 1 << 7 )
84
#define guPANEL_MAIN_PODCASTS ( 1 << 8 )
85
#define guPANEL_MAIN_ALBUMBROWSER ( 1 << 9 )
86
#define guPANEL_MAIN_FILEBROWSER ( 1 << 10 )
87
#define guPANEL_MAIN_JAMENDO ( 1 << 11 )
88
#define guPANEL_MAIN_MAGNATUNE ( 1 << 12 )
89
#define guPANEL_MAIN_LOCATIONS ( 1 << 13 )
90
#define guPANEL_MAIN_SHOWCOVER ( 1 << 14 )
91
#define guPANEL_MAIN_TREEVIEW ( 1 << 15 )
94
#define guPANEL_MAIN_SELECTOR ( guPANEL_MAIN_LIBRARY | guPANEL_MAIN_RADIOS |\
95
guPANEL_MAIN_LASTFM | guPANEL_MAIN_LYRICS |\
96
guPANEL_MAIN_PLAYLISTS | guPANEL_MAIN_PODCASTS |\
97
guPANEL_MAIN_ALBUMBROWSER | guPANEL_MAIN_FILEBROWSER |\
98
guPANEL_MAIN_TREEVIEW )
99
#define guPANEL_MAIN_VISIBLE_DEFAULT ( guPANEL_MAIN_PLAYERPLAYLIST | guPANEL_MAIN_PLAYERFILTERS | \
100
guPANEL_MAIN_SELECTOR )
102
#define guPORTABLEDEVICE_COMMANDS_COUNT 20 // 0 .. 9 Main Window Commands
103
// 10 .. 19 -> Library Pane Windows
105
#define guWINDOW_STATE_NORMAL 0
106
#define guWINDOW_STATE_FULLSCREEN ( 1 << 0 )
107
#define guWINDOW_STATE_MAXIMIZED ( 1 << 1 )
108
#define guWINDOW_STATE_NOSTATUSBAR ( 1 << 3 )
110
enum guUPDATED_TRACKS {
111
guUPDATED_TRACKS_NONE = 0,
112
guUPDATED_TRACKS_PLAYER,
113
guUPDATED_TRACKS_PLAYER_PLAYLIST,
114
guUPDATED_TRACKS_LIBRARY,
115
guUPDATED_TRACKS_PLAYLISTS,
116
guUPDATED_TRACKS_TREEVIEW
120
class guLibUpdateThread;
121
class guLibCleanThread;
122
class guUpdatePodcastsTimer;
123
class guCopyToThread;
124
class guLocationPanel;
126
// -------------------------------------------------------------------------------- //
127
class guMainFrame : public wxFrame
130
wxAuiManager m_AuiManager;
131
unsigned int m_VisiblePanels;
133
guAuiNotebook * m_CatNotebook;
134
wxString m_NBPerspective;
135
wxSplitterWindow * m_PlayerSplitter;
136
guPlayerFilters * m_PlayerFilters;
137
guPlayerPlayList * m_PlayerPlayList;
138
guPlayerVumeters * m_PlayerVumeters;
139
guPlayerPanel * m_PlayerPanel;
140
guLibPanel * m_LibPanel;
141
guRadioPanel * m_RadioPanel;
142
guLastFMPanel * m_LastFMPanel;
143
guLyricsPanel * m_LyricsPanel;
144
guPlayListPanel * m_PlayListPanel;
145
guPodcastPanel * m_PodcastsPanel;
146
guAlbumBrowser * m_AlbumBrowserPanel;
147
guFileBrowser * m_FileBrowserPanel;
148
guJamendoPanel * m_JamendoPanel;
149
guMagnatunePanel * m_MagnatunePanel;
150
guLocationPanel * m_LocationPanel;
151
guCoverPanel * m_CoverPanel;
152
guTreeViewPanel * m_TreeViewPanel;
154
guTaskBarIcon * m_TaskBarIcon;
155
#ifdef WITH_LIBINDICATE_SUPPORT
156
IndicateServer * m_IndicateServer;
158
guStatusBar * m_MainStatusBar;
160
wxMenuItem * m_PlaySmartMenuItem;
161
wxMenuItem * m_LoopPlayListMenuItem;
162
wxMenuItem * m_LoopTrackMenuItem;
165
wxMenu * m_LayoutLoadMenu;
166
wxMenu * m_LayoutDelMenu;
168
wxMenuItem * m_ViewPlayerPlayList;
169
wxMenuItem * m_ViewPlayerFilters;
170
wxMenuItem * m_ViewPlayerSelector;
171
wxMenuItem * m_ViewPlayerVumeters;
172
wxMenuItem * m_ViewMainLocations;
173
wxMenuItem * m_ViewMainShowCover;
174
wxMenuItem * m_ViewLibrary;
175
wxMenuItem * m_ViewLibTextSearch;
176
wxMenuItem * m_ViewLibLabels;
177
wxMenuItem * m_ViewLibGenres;
178
wxMenuItem * m_ViewLibArtists;
179
wxMenuItem * m_ViewLibAlbums;
180
wxMenuItem * m_ViewLibYears;
181
wxMenuItem * m_ViewLibRatings;
182
wxMenuItem * m_ViewLibPlayCounts;
183
wxMenuItem * m_ViewLibComposers;
184
wxMenuItem * m_ViewLibAlbumArtists;
186
wxMenuItem * m_ViewRadios;
187
wxMenuItem * m_ViewRadTextSearch;
188
wxMenuItem * m_ViewRadLabels;
189
wxMenuItem * m_ViewRadGenres;
191
wxMenuItem * m_ViewLastFM;
192
wxMenuItem * m_ViewLyrics;
194
wxMenuItem * m_ViewPlayLists;
195
wxMenuItem * m_ViewPLTextSearch;
197
wxMenuItem * m_ViewAlbumBrowser;
199
wxMenuItem * m_ViewFileBrowser;
201
wxMenuItem * m_ViewJamendo;
202
wxMenuItem * m_ViewJamTextSearch;
203
wxMenuItem * m_ViewJamLabels;
204
wxMenuItem * m_ViewJamGenres;
205
wxMenuItem * m_ViewJamArtists;
206
wxMenuItem * m_ViewJamAlbums;
207
wxMenuItem * m_ViewJamYears;
208
wxMenuItem * m_ViewJamRatings;
209
wxMenuItem * m_ViewJamPlayCounts;
210
wxMenuItem * m_ViewJamComposers;
211
wxMenuItem * m_ViewJamAlbumArtists;
213
wxMenuItem * m_ViewMagnatune;
214
wxMenuItem * m_ViewMagTextSearch;
215
wxMenuItem * m_ViewMagLabels;
216
wxMenuItem * m_ViewMagGenres;
217
wxMenuItem * m_ViewMagArtists;
218
wxMenuItem * m_ViewMagAlbums;
219
wxMenuItem * m_ViewMagYears;
220
wxMenuItem * m_ViewMagRatings;
221
wxMenuItem * m_ViewMagPlayCounts;
222
wxMenuItem * m_ViewMagComposers;
223
wxMenuItem * m_ViewMagAlbumArtists;
225
wxMenuItem * m_ViewPodcasts;
226
wxMenuItem * m_ViewPodChannels;
227
wxMenuItem * m_ViewPodDetails;
229
wxMenuItem * m_ViewTreeView;
230
wxMenuItem * m_ViewTVTextSearch;
232
wxMenuItem * m_ViewFullScreen;
233
wxMenuItem * m_ViewStatusBar;
235
wxMenuItem * m_ForceGaplessMenuItem;
236
wxMenuItem * m_AudioScrobbleMenuItem;
238
wxMenu * m_PortableDevicesMenu;
242
guDbCache * m_DbCache;
243
guJamendoLibrary * m_JamendoDb;
244
guMagnatuneLibrary * m_MagnatuneDb;
245
guLibUpdateThread * m_LibUpdateThread;
246
guLibCleanThread * m_LibCleanThread;
250
guUpdatePodcastsTimer * m_UpdatePodcastsTimer;
252
guPodcastDownloadQueueThread * m_DownloadThread;
253
wxMutex m_DownloadThreadMutex;
255
guDBusServer * m_DBusServer;
259
guGSession * m_GSession;
260
guDBusNotify * m_NotifySrv;
262
guGIO_VolumeMonitor * m_VolumeMonitor;
263
// guPortableMediaLibraryArray m_PortableMediaDbs;
264
// guPortableMediaPanelArray m_PortableMediaPanels;
265
guPortableMediaViewCtrlArray m_PortableMediaViewCtrls;
267
wxWindow * m_CurrentPage;
269
wxLongLong m_SelCount;
270
wxLongLong m_SelLength;
271
wxLongLong m_SelSize;
274
wxSortedArrayString m_LayoutNames;
276
guCopyToThread * m_CopyToThread;
277
wxMutex m_CopyToThreadMutex;
279
guLyricSearchEngine * m_LyricSearchEngine;
280
guLyricSearchContext * m_LyricSearchContext;
282
int m_LoadLayoutPending;
284
void OnUpdateLibrary( wxCommandEvent &event );
285
void OnUpdatePodcasts( wxCommandEvent &event );
286
void OnUpdateCovers( wxCommandEvent &event );
287
void OnUpdateTrack( wxCommandEvent &event );
288
void OnPlayerStatusChanged( wxCommandEvent &event );
289
void OnPlayerTrackListChanged( wxCommandEvent &event );
290
void OnPlayerCapsChanged( wxCommandEvent &event );
291
void OnPlayerVolumeChanged( wxCommandEvent &event );
292
void OnAudioScrobbleUpdate( wxCommandEvent &event );
293
void CreatePortablePlayersMenu( wxMenu * menu );
295
void DoCreateStatusBar( int kind );
296
void OnCloseWindow( wxCloseEvent &event );
297
//void OnIconizeWindow( wxIconizeEvent &event );
298
void OnPreferences( wxCommandEvent &event );
300
void OnPlay( wxCommandEvent &event );
301
void OnStop( wxCommandEvent &event );
302
void OnStopAtEnd( wxCommandEvent &event );
303
void OnClearPlaylist( wxCommandEvent &event );
304
void OnNextTrack( wxCommandEvent &event );
305
void OnPrevTrack( wxCommandEvent &event );
306
void OnNextAlbum( wxCommandEvent &event );
307
void OnPrevAlbum( wxCommandEvent &event );
308
void OnSmartPlay( wxCommandEvent &event );
309
void OnRandomize( wxCommandEvent &event );
310
void OnRepeat( wxCommandEvent &event );
311
void OnAbout( wxCommandEvent &event );
312
void OnHelp( wxCommandEvent &event );
313
void OnCommunity( wxCommandEvent &event );
314
void OnCopyTracksTo( wxCommandEvent &event );
315
void OnCopyTracksToDevice( wxCommandEvent &event );
316
void OnCopyPlayListToDevice( wxCommandEvent &event );
317
void OnUpdateLabels( wxCommandEvent &event );
318
void OnPlayerPlayListUpdateTitle( wxCommandEvent &event );
320
void CheckShowNotebook( void );
321
void CheckHideNotebook( void );
323
void OnGaugeCreate( wxCommandEvent &event );
324
void OnGaugePulse( wxCommandEvent &event );
325
void OnGaugeSetMax( wxCommandEvent &event );
326
void OnGaugeUpdate( wxCommandEvent &event );
327
void OnGaugeRemove( wxCommandEvent &event );
329
void OnSelectTrack( wxCommandEvent &event );
330
void OnSelectAlbum( wxCommandEvent &event );
331
void OnSelectAlbumArtist( wxCommandEvent &event );
332
void OnSelectComposer( wxCommandEvent &event );
333
void OnSelectArtist( wxCommandEvent &event );
334
void OnSelectYear( wxCommandEvent &event );
335
void OnSelectGenre( wxCommandEvent &event );
336
void OnSelectLocation( wxCommandEvent &event );
337
void OnGenreSetSelection( wxCommandEvent &event );
338
void OnAlbumArtistSetSelection( wxCommandEvent &event );
339
void OnComposerSetSelection( wxCommandEvent &event );
340
void OnArtistSetSelection( wxCommandEvent &event );
341
void OnAlbumSetSelection( wxCommandEvent &event );
343
void OnPlayListUpdated( wxCommandEvent &event );
345
void CreateTaskBarIcon( void );
347
void OnPodcastItemUpdated( wxCommandEvent &event );
348
void OnRemovePodcastThread( wxCommandEvent &event );
350
void OnIdle( wxIdleEvent &event );
351
void OnSize( wxSizeEvent &event );
352
void OnPageChanged( wxAuiNotebookEvent& event );
353
void OnPageClosed( wxAuiNotebookEvent& event );
354
void DoPageClose( wxPanel * panel );
356
// void SetLibTracks( wxCommandEvent &event );
357
// void SetRadioStations( wxCommandEvent &event );
358
// void SetPlayListTracks( wxCommandEvent &event );
359
// void SetPodcasts( wxCommandEvent &event );
360
void OnUpdateSelInfo( wxCommandEvent &event );
361
void OnRequestCurrentTrack( wxCommandEvent &event );
363
//void OnSysColorChanged( wxSysColourChangedEvent &event );
365
void OnCreateNewLayout( wxCommandEvent &event );
366
void OnLoadLayout( wxCommandEvent &event );
367
void OnDeleteLayout( wxCommandEvent &event );
368
bool SaveCurrentLayout( const wxString &layoutname );
369
void LoadLayoutNames( void );
370
void CreateLayoutMenus( void );
372
void OnPlayerShowPanel( wxCommandEvent &event );
373
void ShowMainPanel( const int panelid, const bool enable );
375
void OnViewLibrary( wxCommandEvent &event );
376
void OnLibraryShowPanel( wxCommandEvent &event );
378
void OnViewRadio( wxCommandEvent &event );
379
void OnRadioShowPanel( wxCommandEvent &event );
381
void OnViewLastFM( wxCommandEvent &event );
382
void OnViewLyrics( wxCommandEvent &event );
384
void OnViewPlayLists( wxCommandEvent &event );
385
void OnPlayListShowPanel( wxCommandEvent &event );
387
void OnViewPodcasts( wxCommandEvent &event );
388
void OnPodcastsShowPanel( wxCommandEvent &event );
390
void OnViewAlbumBrowser( wxCommandEvent &event );
392
void OnViewFileBrowser( wxCommandEvent &event );
394
void OnViewJamendo( wxCommandEvent &event );
395
void OnJamendoShowPanel( wxCommandEvent &event );
397
void OnViewMagnatune( wxCommandEvent &event );
398
void OnMagnatuneShowPanel( wxCommandEvent &event );
400
void OnViewPortableDevice( wxCommandEvent &event );
401
void OnViewPortableDevicePanel( wxCommandEvent &event );
403
void OnViewTreeView( wxCommandEvent &event );
404
void OnTreeViewShowPanel( wxCommandEvent &event );
406
void OnMainPaneClose( wxAuiManagerEvent &event );
408
void LoadPerspective( const wxString &layout );
409
void LoadTabsPerspective( const wxString &layout );
411
void OnForceUpdateLibrary( wxCommandEvent &event );
412
void OnAddLibraryPath( wxCommandEvent &event );
413
void OnPlayStream( wxCommandEvent &event );
415
void OnViewFullScreen( wxCommandEvent &event );
416
void OnViewStatusBar( wxCommandEvent &event );
418
// There is a bug that dont removes correctly the last window from the AuiNotebook
419
// When a new one is inserted if it was already in the Notebook then
420
// Its shown the last removed tab instead of the new we created.
421
// As a workaround we control if we are going to remove the last window and if so
422
// Instead of remove it we hide the Notebook
423
// When inserting we need to control if it was hiden and if so add the new one and remove the first
424
// We create two functions RemoveTabPanel and InsertTabPanel that controls this
425
void RemoveTabPanel( wxPanel * panel );
426
void InsertTabPanel( wxPanel * panel, const int index, const wxString &label );
428
void OnLibraryCoverChanged( wxCommandEvent &event );
429
void OnJamendoCoverDownloaded( wxCommandEvent &event );
430
void OnMagnatuneCoverDownloaded( wxCommandEvent &event );
431
void OnPlayerPanelCoverChanged( wxCommandEvent &event );
433
void OnVolumeMonitorUpdated( wxCommandEvent &event );
434
void CreatePortableMediaDeviceMenu( wxMenu * menu, const wxString &devicename, const int basecmd );
436
void OnSetForceGapless( wxCommandEvent &event );
437
void OnSetAudioScrobble( wxCommandEvent &event );
439
void OnLyricFound( wxCommandEvent &event );
440
void OnLyricSearchFirst( wxCommandEvent &event );
441
void OnLyricSearchNext( wxCommandEvent &event );
442
void OnLyricSaveChanges( wxCommandEvent &event );
443
void OnLyricExecCommand( wxCommandEvent &event );
445
void OnConfigUpdated( wxCommandEvent &event );
447
void OnChangeVolume( wxCommandEvent &event );
449
void ResetViewMenuState( void );
450
void RefreshViewMenuState( void );
452
void OnSongSetRating( wxCommandEvent &event );
454
void OnSetAllowDenyFilter( wxCommandEvent &event );
456
void OnRaiseWindow( wxCommandEvent &event );
457
void OnLoadPlayList( wxCommandEvent &event );
460
guMainFrame( wxWindow * parent, guDbLibrary * db, guDbCache * dbcache );
462
guDbLibrary * GetDb( void ) { return m_Db; }
463
void DoLibraryClean( wxCommandEvent &event );
464
void LibraryUpdated( wxCommandEvent &event );
465
void OnJamendoUpdated( wxCommandEvent &event );
466
void OnMagnatuneUpdated( wxCommandEvent &event );
467
void LibraryCleanFinished( wxCommandEvent &event );
468
void LibraryReloadControls( wxCommandEvent &event );
469
void OnQuit( wxCommandEvent &event );
470
void OnCloseTab( wxCommandEvent &event );
471
void OnHideCaptions( wxCommandEvent &event );
472
void UpdatePodcasts( void );
474
void RemovePodcastsDownloadThread( void );
475
void AddPodcastsDownloadItems( guPodcastItemArray * items );
476
void RemovePodcastDownloadItems( guPodcastItemArray * items );
478
void UpdatedTracks( int updatedby, const guTrackArray * tracks );
479
void UpdatedTrack( int updatedby, const guTrack * track );
481
guDBusNotify * GetNotifyObject( void ) { return m_NotifySrv; };
483
guJamendoPanel * GetJamendoPanel( void ) { return m_JamendoPanel; }
484
guJamendoLibrary * GetJamendoDb( void )
487
m_JamendoDb = new guJamendoLibrary( wxGetHomeDir() + wxT( "/.guayadeque/Jamendo/Jamendo.db" ) );
490
guMagnatunePanel * GetMagnatunePanel( void ) { return m_MagnatunePanel; }
491
guMagnatuneLibrary * GetMagnatuneDb( void )
494
m_MagnatuneDb = new guMagnatuneLibrary( wxGetHomeDir() + wxT( "/.guayadeque/Magnatune/Magnatune.db" ) );
495
return m_MagnatuneDb;
498
void CreateCopyToMenu( wxMenu * menu, const int basecmd );
500
void CopyToThreadFinished( void );
501
int VisiblePanels( void ) { return m_VisiblePanels; }
503
wxArrayString PortableDeviceVolumeNames( void ) { return m_VolumeMonitor->GetMountNames(); }
505
guPortableMediaViewCtrl * GetPortableMediaViewCtrl( const int basecmd );
506
guPortableMediaViewCtrl * GetPortableMediaViewCtrl( wxWindow * libpanel, const int windowtype = guPANEL_MAIN_LIBRARY );
508
guLyricSearchEngine * LyricSearchEngine( void ) { return m_LyricSearchEngine; }
512
// -------------------------------------------------------------------------------- //
513
class guUpdateCoversThread : public wxThread
520
guUpdateCoversThread( guDbLibrary * db, int gaugeid );
521
~guUpdateCoversThread();
523
virtual ExitCode Entry();
526
// -------------------------------------------------------------------------------- //
527
class guUpdatePodcastsTimer : public wxTimer
531
guMainFrame * m_MainFrame;
534
guUpdatePodcastsTimer( guMainFrame * mainframe, guDbLibrary * db );
536
//Called each time the timer's timeout expires
540
// -------------------------------------------------------------------------------- //
541
class guUpdatePodcastsThread : public wxThread
546
guMainFrame * m_MainFrame;
549
guUpdatePodcastsThread( guDbLibrary * db, guMainFrame * mainframe, int gaugeid );
550
~guUpdatePodcastsThread();
552
virtual ExitCode Entry();
557
// -------------------------------------------------------------------------------- //