summaryrefslogtreecommitdiffstats
path: root/qtspotifymain.h
blob: 2541a8ca1b788878034950c323fc1cfe8776cda8 (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
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTSPOTIFYMAIN_H
#define QTSPOTIFYMAIN_H

#include "ui_qtspotify.h"
#include "audiooutput.h"

#include <QtGui/QMainWindow>

#include <QtCore/QFuture>
#include <QtCore/QFutureWatcher>

class MyStatusBar: public QStatusBar
{
    Q_OBJECT
    Q_PROPERTY(QString statusMessage READ statusMessage WRITE setStatusMessage);
public:
    MyStatusBar(QWidget *parent = 0) : QStatusBar(parent)
    {
        m_label = new QLabel();
        addPermanentWidget(m_label);
    }

    void setStatusMessage(const QString &text)
    {
        m_label->setText(text);
    }

    QString statusMessage() const
    {
        return m_label->text();
    }

private:
    QLabel *m_label;
};

struct despotify_session;
struct track;
struct playlist;
struct search_result;
class QtPlaylist;

class QStateMachine;
class QState;

class LogInDialog;
class CoverDatabase;
class QtSpotifyMain: public QMainWindow
{
    Q_OBJECT
    Q_PROPERTY(QString debuggingMessage READ debuggingMessage WRITE debug)
public:
    QtSpotifyMain(QWidget *parent = 0);
    ~QtSpotifyMain();


    // Just a dummy so we can use the property mechanism to call the debug() function
    QString debuggingMessage() const { return QString(); }

    bool debugging() const { return m_debugging; }

protected:
    bool event(QEvent *event);

private slots:
    void logIn();
    void endSession();
    void retrievePlayLists();
    void populateSearchBox();
    void play();
    void pause();
    void stop();
    void resume();
    void selectPlayList();
    void selectSearch();
    void decideLoginResult();    
    void debug(const QString &text);
    void setDebugging(bool on) { m_debugging = on; }
    void search();    
    void skip();
    void previous();
    void searchMore();
    void playlistActivated(const QModelIndex &index);

signals:
    void loggedIn();
    void loginFailed();
    void searched();
    void playlistItemActivated();

private:
    void setPlaylist(QList<track *> tracks);

    void initUi();
    void initWatchers();

    void initMachine();
    void initLoggingInState(QState *);
    void initLoggedInState(QState *);
    void initPlayListHandlingState(QState *);
    void initPlayBackHandlingState(QState *);
    void initPlayingState(QState *);
    void initIdleState(QState *);
    void setNewTrack(track *t);
    void selectTrack(track *t);
    void selectSearchOrPlaylist(QListView *listView);

    Ui_QtSpotifyMain m_ui;
    despotify_session *m_session;

    playlist *m_rootPlaylist;
    QStateMachine *m_machine;
    CoverDatabase *m_coverDatabase;

    QList<QtPlaylist *> m_searches;

    bool m_debugging;

    QFutureWatcher<bool> *m_authenticationWatcher;
    QFutureWatcher<playlist *> *m_retrievingPlayListWatcher;

    LogInDialog *m_logInDialog;

    AudioOutput m_audio;
};

#endif // QTSPOTIFYMAIN_H