-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathampacheserver.h
166 lines (123 loc) · 3.8 KB
/
ampacheserver.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
This file is part of Waver
Copyright (C) 2021 Peter Papp
Please visit https://launchpad.net/waver for details
*/
#ifndef AMPACHESERVER_H
#define AMPACHESERVER_H
#include <QByteArray>
#include <QCryptographicHash>
#include <QDateTime>
#include <QGuiApplication>
#include <QHash>
#include <QMultiHash>
#include <QLatin1String>
#include <QList>
#include <QMutex>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QObject>
#include <QSettings>
#include <QString>
#include <QStringList>
#include <QThread>
#include <QTimer>
#include <QUrl>
#include <QUrlQuery>
#include <QUuid>
#include <QXmlStreamAttribute>
#include <QXmlStreamAttributes>
#include <QXmlStreamReader>
#ifdef QT_DEBUG
#include <QDebug>
#endif
#include "globals.h"
#include "qt5keychain/keychain.h"
using namespace QKeychain;
class AmpacheServer : public QObject
{
Q_OBJECT
public:
enum OpCode {
Search,
SearchAlbums,
BrowseRoot,
BrowseArtist,
BrowseAlbum,
CountFlagged,
PlaylistRoot,
PlaylistSongs,
RadioStations,
SetFlag,
Shuffle,
Artist,
Song,
Tags,
Unknown
};
typedef QHash<QString, QString> OpData;
typedef QList<OpData> OpResults;
explicit AmpacheServer(QUrl host, QString user, QObject *parent = nullptr);
long getServerVersion();
QUrl getHost();
QString getUser();
QString formattedName();
void setId(QString id);
void setSettingsId(QUuid settingsId);
QString getId();
QUuid getSettingsId();
void setShuffleTags(QStringList selectedTags);
bool isShuffleTagsSelected();
bool isShuffleTagSelected(int tagId);
void setPassword(QString psw);
void retreivePassword();
void startOperation(OpCode opCode, OpData opData, QObject *extra = nullptr);
private:
struct Operation {
OpCode opCode;
OpData opData;
QObject *extra;
};
static const long SERVER_API_VERSION_MIN = 5000000;
QUrl host;
QString psw;
QString user;
QString id;
QUuid settingsId;
bool handshakeInProgress;
bool sessionExpiredHandshakeStarted;
QString authKey;
long serverVersion;
int songCount;
int flaggedCount;
int shuffled;
OpResults shuffleRegular;
OpResults shuffleFavorites;
OpResults shuffleRecentlyAdded;
bool shuffleRegularCompleted;
bool shuffleFavoritesCompleted;
bool shuffleRecentlyAddedCompleted;
QMutex opQueueMutex;
QList<Operation> opQueue;
QList<int> shuffleTags;
WritePasswordJob *writeKeychainJob;
ReadPasswordJob *readKeychainJob;
QNetworkAccessManager networkAccessManager;
QNetworkRequest buildRequest(QUrlQuery query, QObject *extra);
long apiVersionFromString(QString apiVersionString);
QStringList shuffleTagsToStringList();
QString tagIdToString(int tagId);
QObject *copyExtra(QObject *extra);
private slots:
void writeKeychainJobFinished(QKeychain::Job* job);
void readKeychainJobFinished(QKeychain::Job* job);
void startHandshake();
void startOperations();
void networkFinished(QNetworkReply *reply);
signals:
void operationFinished(OpCode opCode, OpData opData, OpResults opResults);
void errorMessage(QString id, QString info, QString error);
void passwordNeeded(QString id);
};
#endif // AMPACHESERVER_H