-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwidget.h
148 lines (120 loc) · 3.89 KB
/
mainwidget.h
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
/*
* This file is part of Spokify.
* Copyright (C) 2010 Rafael Fernández López <ereslibre@kde.org>
*
* Spokify is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Spokify 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Spokify. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include "chunk.h"
#include "trackmodel.h"
#include <QtCore/QModelIndex>
#include <QtCore/QPersistentModelIndex>
#include <QtGui/QWidget>
#include <QtGui/QItemSelection>
#include <QtGui/QSortFilterProxyModel>
#include <libspotify/api.h>
class TrackView;
class QLabel;
class QSlider;
class QTabWidget;
class QSortFilterProxyModel;
class KLineEdit;
class Chunk;
class Slider;
class PlayPauseButton;
class BlockAnalyzer;
class MainWidget
: public QWidget
{
Q_OBJECT
public:
enum State {
Stopped = 0,
Playing,
Paused
};
enum Focus {
SetFocus = 0,
DoNotSetFocus = 1
};
struct Collection {
Collection()
: proxyModel(0)
, trackModel(0)
, needsToBeFilled(true)
{
}
int rowForTrack(sp_track *track)
{
for (int i = 0; i < proxyModel->rowCount(); ++i) {
sp_track *const currTrack = proxyModel->index(i, 0).data(TrackModel::SpotifyNativeTrackRole).value<sp_track*>();
if (currTrack == track) {
return i;
}
}
return -1;
}
QSortFilterProxyModel *proxyModel;
TrackModel *trackModel;
sp_track *currentTrack;
bool needsToBeFilled;
};
MainWidget(QWidget *parent = 0);
virtual ~MainWidget();
void loggedIn();
void loggedOut();
void clearFilter();
Collection &collection(sp_playlist *playlist);
Collection &collection(sp_search *search);
Collection *currentPlayingCollection() const;
void setCurrentPlayingCollection(Collection &collection);
TrackView *trackView() const;
void setState(State state);
State state() const;
void highlightCurrentTrack(Focus focus = SetFocus);
void setTotalTrackTime(int totalTrackTime);
void advanceCurrentTrackTime(const Chunk &c);
void advanceCurrentCacheTrackTime(const Chunk &c);
Q_SIGNALS:
void play(const QModelIndex &index);
void resume();
void pausedOrStopped();
void seekPosition(int position);
void currentTrackFinished();
public Q_SLOTS:
void updateAnalyzer(const Chunk &chunk);
private Q_SLOTS:
void playSlot();
void pauseSlot();
void togglePlayPauseSlot();
void trackRequested(const QModelIndex &index);
void selectionChangedSlot(const QItemSelection &selection);
void layoutChangedSlot();
void sliderSeekSlot(float position);
private:
State m_state;
KLineEdit *m_filter;
TrackView *m_trackView;
PlayPauseButton *m_playPauseButton;
Slider *m_slider;
QLabel *m_currTotalTime;
BlockAnalyzer *m_analyzer;
int m_totalTrackTime;
QHash<sp_playlist*, Collection> m_trackModelPlaylistCache;
QHash<sp_search*, Collection> m_trackModelSearchCache;
Collection *m_currentCollection;
Collection *m_currentPlayingCollection;
};
#endif