~ubuntu-branches/ubuntu/lucid/lastfm/lucid

« back to all changes in this revision

Viewing changes to src/SideBarModel.h

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-12-31 09:49:54 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071231094954-ix1amvcsj9pk61ya
Tags: 1:1.4.1.57486.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #180254), remaining changes:
  - debian/rules;
    - Added dh_icons
  - Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
*   Copyright (C) 2005 - 2007 by                                          *
 
3
 *      Christian Muehlhaeuser, Last.fm Ltd <chris@last.fm>                *
 
4
*      Max Howell, Last.fm Ltd <max@last.fm>                              *
 
5
*                                                                         *
 
6
*   This program is free software; you can redistribute it and/or modify  *
 
7
*   it under the terms of the GNU General Public License as published by  *
 
8
*   the Free Software Foundation; either version 2 of the License, or     *
 
9
*   (at your option) any later version.                                   *
 
10
*                                                                         *
 
11
*   This program is distributed in the hope that it will be useful,       *
 
12
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
*   GNU General Public License for more details.                          *
 
15
*                                                                         *
 
16
*   You should have received a copy of the GNU General Public License     *
 
17
*   along with this program; if not, write to the                         *
 
18
*   Free Software Foundation, Inc.,                                       *
 
19
*   51 Franklin Steet, Fifth Floor, Boston, MA  02110-1301, USA.          *
 
20
***************************************************************************/
 
21
 
 
22
 
 
23
#ifndef SIDE_BAR_MODEL_H
 
24
#define SIDE_BAR_MODEL_H
 
25
 
 
26
#include <QAbstractItemModel>
 
27
#include <QStringList>
 
28
#include <QPixmap>
 
29
#include <QIcon>
 
30
#include <QHash>
 
31
 
 
32
#include "RadioEnums.h"
 
33
#include "WeightedStringList.h"
 
34
#include "Station.h"
 
35
#include "Track.h"
 
36
 
 
37
namespace SideBar
 
38
{
 
39
    enum Type
 
40
    {
 
41
        MyProfile = 0,
 
42
        Spacer1, /**/
 
43
        StartAStation,
 
44
        NowPlaying,
 
45
        Spacer2, /**/
 
46
        MyRecommendations,
 
47
        PersonalRadio,
 
48
        LovedTracksRadio,
 
49
        NeighbourhoodRadio,
 
50
        Spacer3, /**/
 
51
        RecentlyPlayed,
 
52
        RecentlyLoved,
 
53
        RecentlyBanned,
 
54
        MyTags,
 
55
        Friends,
 
56
        Neighbours,
 
57
        History,
 
58
        
 
59
        /// don't touch me!
 
60
        RowCount,
 
61
        
 
62
        FriendsChild,
 
63
        NeighboursChild,
 
64
        MyTagsChild,
 
65
        RecentlyBannedTrack,
 
66
        RecentlyPlayedTrack,
 
67
        RecentlyLovedTrack,
 
68
        HistoryStation,
 
69
        
 
70
        /// don't touch me!
 
71
        TypeUnknown
 
72
    };
 
73
    
 
74
    enum Role
 
75
    {
 
76
        StationUrlRole = Qt::UserRole,
 
77
        UrlRole,
 
78
        TrackRole
 
79
    };
 
80
    
 
81
    enum SortOrder
 
82
    {
 
83
        MostWeightOrder,
 
84
        AscendingOrder,
 
85
        DescendingOrder
 
86
    };
 
87
}
 
88
 
 
89
 
 
90
class QUrl;
 
91
 
 
92
class SideBarModel : public QAbstractItemModel
 
93
{
 
94
    Q_OBJECT
 
95
    
 
96
public:
 
97
    SideBarModel();
 
98
    
 
99
    void addRecentlyPlayedTrack( Track );
 
100
    
 
101
    /** Reimplimentations */
 
102
    QVariant data(const QModelIndex &index, int role) const;
 
103
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
 
104
    QModelIndex parent(const QModelIndex &index) const;
 
105
    int rowCount( const QModelIndex &parent = QModelIndex() ) const;
 
106
    Qt::ItemFlags flags( const QModelIndex& ) const;
 
107
    QMimeData *mimeData( const QModelIndexList& indexes ) const;
 
108
    QStringList mimeTypes() const;
 
109
    
 
110
    /** no header, one column always */
 
111
    QVariant headerData( int, Qt::Orientation, int ) const { return QVariant(); }
 
112
    int columnCount( const QModelIndex& ) const { return 1; }
 
113
    
 
114
    void sortTags( WeightedStringList tagsToSort, SideBar::SortOrder sortOrder );
 
115
    void sortTags( SideBar::SortOrder sortOrder );
 
116
    void sortNeighbours( QStringList neighboursToSort, SideBar::SortOrder );
 
117
    void sortNeighbours( SideBar::SortOrder sortOrder );
 
118
    
 
119
private slots:
 
120
    void onResult( Request* );
 
121
    void onAvatarDownloaded( QByteArray );
 
122
    void onAppEvent( int, const QVariant& );
 
123
    void updateHistory();
 
124
    
 
125
private:
 
126
    QStringList m_friends;
 
127
    QStringList m_neighbours;
 
128
    QStringList m_neighboursBySimilarity;
 
129
    
 
130
    QList<Track> m_banned;
 
131
    QList<Track> m_loved;
 
132
    QList<Track> m_played;
 
133
    WeightedStringList m_tags;
 
134
    QList<Station> m_history;
 
135
 
 
136
    void queueAvatarsDownload( const QMap<QString, QString>& urls );
 
137
    void downloadAvatar( const QString& user, const QUrl& url );
 
138
    void emitRowChanged( int parent_row, int child_row = -1 );
 
139
    
 
140
    template <class T> void changeData( int row, T& old_data, const T& new_data );
 
141
    
 
142
    QPixmap m_avatar;
 
143
    
 
144
    bool m_track_is_playing;
 
145
    
 
146
    QString m_change_station_text;
 
147
    QMap<QString, QString> m_avatarQueue;
 
148
    QHash<QString, QIcon> m_avatars;
 
149
};
 
150
 
 
151
 
 
152
class SideBarItem
 
153
{
 
154
public:
 
155
    SideBarItem( const QModelIndex& );
 
156
    
 
157
    enum Classification
 
158
    {
 
159
        Station,
 
160
        Track,
 
161
        Tag,
 
162
        User,
 
163
        ClassNone
 
164
    };
 
165
    
 
166
    SideBar::Type type() const { return m_type; }
 
167
    Classification classification() const { return m_classification; }
 
168
    QIcon icon() const;
 
169
    ::Track track() const;
 
170
    ::Station station() const;
 
171
    
 
172
private:
 
173
    Classification m_classification;
 
174
    SideBar::Type m_type;
 
175
    
 
176
    QModelIndex m_index;
 
177
};
 
178
 
 
179
#endif