~ubuntu-branches/ubuntu/vivid/guayadeque/vivid

« back to all changes in this revision

Viewing changes to src/Magnatune.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-02-25 11:59:10 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110225115910-13phl46pz0rgqg0a
Tags: 0.2.9-1
* Imported Upstream version 0.2.9
* Drop 02-google_cover_search_engine_crash.patch patch, applied upstream.

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
#ifndef MAGNATUNE_H
 
22
#define MAGNATUNE_H
 
23
 
 
24
#include "Config.h"
 
25
#include "LibPanel.h"
 
26
#include "DbLibrary.h"
 
27
#include "Preferences.h"
 
28
 
 
29
#include <wx/string.h>
 
30
#include <wx/window.h>
 
31
 
 
32
#define guMAGNATUNE_DATABASE_DUMP_URL         wxT( "http://he3.magnatune.com/info/album_info_xml.gz" )
 
33
//#define guMAGNATUNE_FILE_STREAM_URL
 
34
#define guMAGNATUNE_STREAM_FORMAT_MP3         wxT( ".mp3" )
 
35
#define guMAGNATUNE_STREAM_FORMAT_OGG         wxT( ".ogg" )
 
36
 
 
37
#define guMAGNATUNE_ACTION_UPDATE             0   // Download the database and then upgrade
 
38
#define guMAGNATUNE_ACTION_UPGRADE            1   // Just refresh the tracks not updating the database
 
39
 
 
40
#define guMAGNATUNE_PARTNER_ID                wxT( "guayadeque" )
 
41
#define guMAGNATUNE_DOWNLOAD_URL              wxT( "http://%s:%s@download.magnatune.com/buy/membership_free_dl_xml.php?sku=%s&id=guayadeque" )
 
42
 
 
43
enum guMagnatune_Membership {
 
44
    guMAGNATUNE_MEMBERSHIP_FREE,
 
45
    guMAGNATUNE_MEMBERSHIP_STREAM,
 
46
    guMAGNATUNE_MEMBERSHIP_DOWNLOAD
 
47
};
 
48
 
 
49
// -------------------------------------------------------------------------------- //
 
50
class guMagnatuneLibrary : public guDbLibrary
 
51
{
 
52
  public :
 
53
    guMagnatuneLibrary( const wxString &libpath );
 
54
    ~guMagnatuneLibrary();
 
55
 
 
56
    virtual void        UpdateArtistsLabels( const guArrayListItems &labelsets );
 
57
    virtual void        UpdateAlbumsLabels( const guArrayListItems &labelsets );
 
58
    virtual void        UpdateSongsLabels( const guArrayListItems &labelsets );
 
59
 
 
60
    void                CreateNewSong( guTrack * track, const wxString &albumsku, const wxString &coverlink );
 
61
    int                 GetTrackId( const wxString &url, guTrack * track = NULL );
 
62
 
 
63
    wxString            GetAlbumSku( const int trackid );
 
64
};
 
65
 
 
66
// -------------------------------------------------------------------------------- //
 
67
class guMagnatuneUpdateThread : public wxThread
 
68
{
 
69
  private :
 
70
    guMagnatuneLibrary *    m_Db;
 
71
    guMainFrame *           m_MainFrame;
 
72
    int                     m_GaugeId;
 
73
    int                     m_Action;
 
74
    wxSortedArrayString     m_GenreList;
 
75
    wxArrayString           m_AllowedGenres;
 
76
    guTrack                 m_CurrentTrack;
 
77
    wxString                m_AlbumSku;
 
78
    wxString                m_CoverLink;
 
79
 
 
80
    bool                UpdateDatabase( void );
 
81
    void                ReadMagnatuneXmlTrack( wxXmlNode * xmlnode );
 
82
    void                ReadMagnatuneXmlAlbum( wxXmlNode * xmlnode );
 
83
    void                AddGenres( const wxString &genre );
 
84
 
 
85
 
 
86
  protected :
 
87
 
 
88
  public :
 
89
    guMagnatuneUpdateThread( guMagnatuneLibrary * db, const int action, int gaugeid );
 
90
    ~guMagnatuneUpdateThread();
 
91
 
 
92
    ExitCode Entry();
 
93
 
 
94
};
 
95
 
 
96
class guMagnatuneDownloadThread;
 
97
 
 
98
// -------------------------------------------------------------------------------- //
 
99
class guMagnatunePanel : public guLibPanel
 
100
{
 
101
  protected :
 
102
    int                         m_Membership;
 
103
    wxString                    m_UserName;
 
104
    wxString                    m_Password;
 
105
    guMagnatuneUpdateThread *   m_UpdateThread;
 
106
    wxMutex                     m_UpdateThreadMutex;
 
107
 
 
108
    virtual void                NormalizeTracks( guTrackArray * tracks, const bool isdrag = false );
 
109
    virtual void                CreateContextMenu( wxMenu * menu, const int windowid = 0 );
 
110
    void                        OnEditSetup( wxCommandEvent &event );
 
111
 
 
112
    void                        OnUpdate( wxCommandEvent &event );
 
113
    void                        OnUpgrade( wxCommandEvent &event );
 
114
    void                        StartUpdateTracks( const int action );
 
115
 
 
116
    void                        OnConfigUpdated( wxCommandEvent &event );
 
117
    void                        OnCoverDownloaded( wxCommandEvent &event );
 
118
 
 
119
    void                        OnAlbumDownloadCoverClicked( wxCommandEvent &event );
 
120
    void                        OnAlbumSelectCoverClicked( wxCommandEvent &event );
 
121
 
 
122
    void                        OnDownloadAlbum( wxCommandEvent &event );
 
123
    void                        OnDownloadTrackAlbum( wxCommandEvent &event );
 
124
 
 
125
    void                        DownloadAlbums( const wxArrayInt &albumids );
 
126
 
 
127
  public :
 
128
    guMagnatunePanel( wxWindow * parent, guMagnatuneLibrary * db, guPlayerPanel * playerpanel, const wxString &prefix = wxT( "Jam" ) );
 
129
    ~guMagnatunePanel();
 
130
 
 
131
    guMagnatuneLibrary *        GetMagnatuneDb( void ) { return ( guMagnatuneLibrary * ) m_Db; }
 
132
    wxImage *                   GetAlbumCover( const int albumid, const wxString &artist, const wxString &album, wxString &coverpath );
 
133
    void                        AddDownload( const int albumid, const wxString &artist, const wxString &album );
 
134
 
 
135
    void                        EndUpdateThread( void );
 
136
 
 
137
 
 
138
};
 
139
 
 
140
// -------------------------------------------------------------------------------- //
 
141
class guMagnatuneDownloadThread : public wxThread
 
142
{
 
143
  protected :
 
144
    guMagnatuneLibrary *    m_Db;
 
145
    guMagnatunePanel *      m_MagnatunePanel;
 
146
    wxString                m_ArtistName;
 
147
    wxString                m_AlbumName;
 
148
    int                     m_AlbumId;
 
149
 
 
150
  public :
 
151
    guMagnatuneDownloadThread( guMagnatunePanel * jamendopanel, const int albumid,
 
152
                                const wxString &artist, const wxString &album );
 
153
    ~guMagnatuneDownloadThread();
 
154
 
 
155
    ExitCode Entry();
 
156
 
 
157
};
 
158
 
 
159
#endif
 
160
// -------------------------------------------------------------------------------- //