summaryrefslogtreecommitdiffstats
path: root/amarok/src/magnatunebrowser/magnatunebrowser.h
blob: 5c4948eae76425f0a5f110397cc023e4d0473428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
  Copyright (c) 2006  Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library 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
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  Boston, MA 02110-1301, USA.
*/

#ifndef AMAROKMAGNATUNEBROWSER_H
#define AMAROKMAGNATUNEBROWSER_H


#include "amarok.h"
#include "magnatuneartistinfobox.h"
#include "magnatunelistview.h"
#include "magnatunelistviewitems.h"
#include "magnatunepurchasedialog.h"
#include "magnatunepurchasehandler.h"
#include "magnatuneredownloadhandler.h"
#include "magnatunexmlparser.h"

#include <kio/job.h>
#include <kio/jobclasses.h>

#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqhbox.h>
#include <tqpopupmenu.h>
#include <tqpushbutton.h>
#include <tqvbox.h>



/**
Amarok browser that displays all the music available at magnatune.com and makes it available for previewing and purchasing.
Implemented as a singleton

@author Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>
*/
class MagnatuneBrowser : public TQVBox
{
    Q_OBJECT
  

public:
    /**
     * Destructor
     */
    ~MagnatuneBrowser() { }

    /**
     * Retrieves the class instance (Singleton pattern)
     * @return pointer to the class instance
     */
    static MagnatuneBrowser *instance() {
        if(!s_instance)  s_instance = new MagnatuneBrowser("MagnatuneBrowser");
        return s_instance;
    }

private slots:

    /**
     * Slot for recieving aboutToShow signals from the right click menu.
     * Inserts items in the menu based on the type of the current selection
     */
    void menuAboutToShow();

    /**
     * Slot called when the purchase album button is clicked. Starts a purchase
     */
    void purchaseButtonClicked();

    /**
     * Slot for recieving notification from the right click menu that the user
     * has chosen to purchase an album. Starts a purchase
     */
    void purchaseSelectedAlbum();

    /**
     * Slot for recieving notification from the right click menu that the user 
     * has chosen to purchase the album contining the selected track.
     * Starts a purchase
     */
    void purchaseAlbumContainingSelectedTrack();

     /**
     * Slot for recieving notification from the right click menu that the user 
     * has selected "add to playlist" for the currently selected item,
     */
    void addSelectionToPlaylist();

    /**
     * Slot for recieving notification that the user has double clicked an 
     * item in the list view. Ads item to playlist.
     * @param item The item that was double clicked
     */
    void itemExecuted( TQListViewItem * item);

    /**
     * Slot for recieving notification when a new item in the list is selected.
     * Adds the corrosponding artist or album info to the info view (if visible)
     * @param item The selected item
     */
    void selectionChanged( TQListViewItem * item);

    /**
     * Slot for recieving notifications about right clicks in the list view.
     * if selection is valid the popup menu is shown
     * @param item The item that was right clicked
     * @param pos The position of the cursor at the time of thre right click
     * @param column The column of the item that was right clicked (unused)
     */
    void showPopupMenu( TQListViewItem * item, const TQPoint & pos, int column );

    /**
     * Slot for recieving notification that the update button has been clicked.
     */
    void updateButtonClicked();

    /**
     * Toggles the info area on and off
     * @param show If true the info box is shown, if false it is hidden
     */
    void showInfo(bool show);

    /**
     * Slot for recieving notification when the Magnatune xml file has been downloaded. 
     * Triggers a parse of the file to get the info added to the databse
     * @param downLoadJob The calling download Job
     */
    void listDownloadComplete( TDEIO::Job* downLoadJob);

    /**
     * Slot for catching cancelled list downloads
     */
    void listDownloadCancelled();

    /**
     * Slot called when the genre combo box selection changes. Triggers an update of the list view.
     */
    void genreChanged();

    /**
     * Slot called when the parsing of the Magnatuin xml file is completed.
     * Triggers an update of the list view and the genre combo box
     */
    void doneParsing();

    /**
     * Starts the process of redownloading a previously bought album
     */
    void processRedownload();

    /**
     * Slot for recieving notifications of completed purchase operations
     * @param success Was the operation a success?
     */
    void purchaseCompleted( bool success );

    
    /**
     * Don not do expensive initializations before we are actually shown
     */
    void polish();

private:

    MagnatuneBrowser( const char *name );

    /**
     * Helper function that initializes the button panel below the list view
     */
    void initBottomPanel();

    /**
     * Helper function that initializes the genre selection panel above the list view
     */
    void initTopPanel();

    /**
     * Starts downloading an updated track list xml file from 
     * http://magnatune.com/info/album_info.xml
     * @return Currently always returns true
     */
    bool updateMagnatuneList();

    /**
     * Adds a magnatune preview track to the playlist.
     * @param item The track to add
     */
    void addTrackToPlaylist ( MagnatuneTrack  *item );

    /**
     * Adds all preview tracks on a magnatune album to the playlist
     * @param item The album to add
     */
    void addAlbumToPlaylist ( MagnatuneAlbum  *item );

    /**
     * Adds all preview tracks on all albums by a given artist to the playlist
     * @param item the artist to add
     */
    void addArtistToPlaylist( MagnatuneArtist *item );

    /**
     * Clears the list view and inserts artists based on the currently selected genre
     */
    void updateList();

    /**
     * Clears the genre combo box and inserts all genres from the database
     */
    void updateGenreBox();


    static MagnatuneBrowser *s_instance;

    MagnatuneListView         *m_listView;
    MagnatuneArtistInfoBox    *m_artistInfobox;
    TQString                    m_currentInfoUrl;
    TQPopupMenu                *m_popupMenu;
    MagnatunePurchaseHandler  *m_purchaseHandler;
    MagnatuneRedownloadHandler *m_redownloadHandler;

    TQHBox       *m_topPanel;
    TQVBox       *m_bottomPanel;
    TQPushButton *m_advancedFeaturesButton;
    TQPushButton *m_updateListButton;
    TQPushButton *m_purchaseAlbumButton;
    TQPushButton *m_showInfoToggleButton;

    TQComboBox   *m_genreComboBox;
    bool         m_isInfoShown;
    bool         m_purchaseInProgress;
    bool         m_polished;

    TQString      m_tempFileName;

    TDEIO::TransferJob * m_listDownloadJob;
};


#endif